Generate Jupyter notebooks.
Project description
herzog
Write your Python Jupyter notebooks in herzog!
herzog scripts are pure Python. This means version control, pull requests, CI/CD, and more.
Great! How does it work?
Usage
Use context managers to define Jupyter cells:
with herzog.Cell("python"):
print("Hello herzog")
Want to tell your users what to do? Make a markdown cell:
with herzog.Cell("markdown"):
"""
# How cool is this notebook?
So cool!
"""
Use the herzog CLI to generate a notebook from your Python script:
herzog path/to/my/cool_script.py > path/to/my/cool_notebook.ipynb
Example
The script below, which can be found in the herzog repo, has been generated into a notebook as shown here.
Note that everything outside herzog context managers is not included in the notebook. That's where you put tests, developer notes, salacious accusations, or anything else.
import herzog
with herzog.Cell("markdown"):
"""
# Fibonacci:
Recursively generate terms from the Fibonacci sequence.
"""
with herzog.Cell("python"):
def fibonacci(term: int) -> int:
"""
0-indexed fibonacci
"""
assert 0 <= term
if 1 < term:
return fibonacci(term - 1) + fibonacci(term - 2)
else:
return term
# Code outside herzog context does not appear in generated notebooks.
try:
fibonacci(-1)
except AssertionError:
# expected
pass
expected_fibonacci = (0, 1, 1, 2, 3, 5, 8, 13, 21)
for i in range(1, len(expected_fibonacci)):
assert expected_fibonacci[i] == fibonacci(i)
golden_ratio = (1 + 5 ** 0.5) / 2
assert 1e-10 > abs(golden_ratio - fibonacci(26) / fibonacci(25))
Installation
pip install git+https://github.com/xbrianh/herzog
Links
Project home page GitHub
Bugs
Please report bugs, issues, feature requests, etc. on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file herzog-0.0.2.tar.gz
.
File metadata
- Download URL: herzog-0.0.2.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74f882e6436ec9cbd8ebf9755d8bb586d25f39667e1b9fc8c68201cad8f41c4c |
|
MD5 | 4d30ce1eaec38b994f30b46b1e99bbe2 |
|
BLAKE2b-256 | d8a184159267e9a8427ec851e681c3a192cdb66461a8d492c8a1d6d03716ccbc |