pidgy examples¤
this notebook demonstrates pidgy syntax. we begin by initializing the pidgy extension.
it is possible to use a pidgy kernel instead of the extension, but for testing purposes we use the extension.
%reload_ext pidgy
<details>
<summary>hidden settings for testing this notebook</summary>
<p>out of the box, `pidgy` is asynchrous and reactive, but to use this document for testing we have to constrain the execution to synchronous and blocking. </p>
%matplotlib agg
shell.weave.reactive = False
shell.weave.template_cls = pidgy.weave.IPythonMarkdown
from pidgy import get_ipython
</details>
hidden settings for testing this notebook
out of the box, `pidgy` is asynchrous and reactive, but to use this document for testing we have to constrain the execution to synchronous and blocking.
%matplotlib agg shell.weave.reactive = False shell.weave.template_cls = pidgy.weave.IPythonMarkdown from pidgy import get_ipythonan indent can make a big different¤
under normal cirumstances, the following line of code is valid python, but in pidgy it is valid markdown and we observe this visually.
print("this is a markdown paragraph")
print("this is a markdown paragraph")
compare the previous woven display with the following that indents the code. we notice the output in typeset as a monospace font rather than the prior rich typeface.
print("this is an indented code block")
print("this is an indented code block")
that is really all there is to pidgy. we must indent the code, as follows, to make sure execution is engaged. indent your code, and tell good stories.
indenting code in notebooks is a useful practice, unindented code rendered as markdown appears as rich text and is not canonical.
suppressing the woven display¤
begin a cell with a single empty line to suppress a display. the following code is execute but
print("the input source is not shown because the code block begins with a blank line")
## all markdown is a string
in `pidgy`, markdown and python can cooperate.
the primary way this is acheived is by representing markdown blocks as block quotes rather than comments.
as strings, markdown can join the party.
we start slow by defining a markdown paragraph to a variable name `paragraph`
paragraph =\
imagine you wrote a really cool paragraph.
it has words, sentences, and drama.
you have a word limit and you need to count the words.
with `paragraph` saved as a variable it becomes easy to count our words.
Markdown(F"the `paragraph` has {len(paragraph.split())} words") # pidgy exposes IPython display in the primary namespace
the paragraph has 38 words
all markdown is a string¤
in pidgy, markdown and python can cooperate.
the primary way this is acheived is by representing markdown blocks as block quotes rather than comments.
as strings, markdown can join the party.
we start slow by defining a markdown paragraph to a variable name paragraph
paragraph =\
imagine you wrote a really cool paragraph. it has words, sentences, and drama. you have a word limit and you need to count the words.
with paragraph saved as a variable it becomes easy to count our words.
Markdown(F"the `paragraph` has {len(paragraph.split())} words") # pidgy exposes IPython display in the primary namespace
connecting markdown and indented python code¤
### docstrings
docstrings¤
line continuations¤
parenthesis¤
templating markdown¤
so far we have discussed two cooperative syntaxes: markdown and python.
the last major piece to pidgy are jinja2 templates that allow python variables to be
woven into rich, interactive displays.
pidgy extends markdown by being aware of jinja2 templates that can include live data into woven displays
{{df.describe().T}}
import pandas
df = pandas.DataFrame([x, 0, 0 ] for x in range(10))
| count | mean | std | min | 25% | 50% | 75% | max | |
|---|---|---|---|---|---|---|---|---|
| 0 | 10.0 | 4.5 | 3.02765 | 0.0 | 2.25 | 4.5 | 6.75 | 9.0 |
| 1 | 10.0 | 0.0 | 0.00000 | 0.0 | 0.00 | 0.0 | 0.00 | 0.0 |
| 2 | 10.0 | 0.0 | 0.00000 | 0.0 | 0.00 | 0.0 | 0.00 | 0.0 |
import pandas
df = pandas.DataFrame([x, 0, 0 ] for x in range(10))
iframes and images¤
https://nbviewer.org/github/deathbeds/pidgy/blob/master/docs/tangle_examples.ipynb