Skip to main content

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

An example herzog script is shown below, along with the generated notebook. Both the herzog source and generated notebook can be found in the herzog repository.

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))

Rendered Fibonacci notebook

Installation

pip install herzog

Links

Project home page GitHub
Package distribution PyPI

Bugs

Please report bugs, issues, feature requests, etc. on GitHub.

Metadata

Release files for herzog 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for herzog 0.1.0
File Size Uploaded
herzog-0.1.0.tar.gz 5.0 kB Details

Release files / herzog-0.1.0.tar.gz

Download URL herzog-0.1.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
71715b5cf0a64a9ef5c51ad1caa2a2c98061c62cd646297423fa4de48ce376e1
BLAKE2b-256 checksum
How to use checksums
c8e78c9bbea22d92d74c5edb984e4c6fd04afe0fac869b04dae60856aabf0b44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

0.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page