Skip to main content

pypad-notebook

Read, write and convert PyPad notebooks (.pypad.py) and Jupyter notebooks (.ipynb). Standard library only; Python 3.9+.

PyPad is a small in-browser Python notebook for teaching: it runs entirely in the learner's browser, fits in a Moodle quiz question, can be shared as a link, and its files are plain, readable Python. This package is the file-format side of it, so a notebook is never trapped.

pip install pypad-notebook

Command line

pypad convert lesson.pypad.py            # -> lesson.ipynb
pypad convert lesson.ipynb                # -> lesson.pypad.py
pypad convert lesson.ipynb --outputs text
pypad check lesson.pypad.py              # ok / changed / absent: is it still what PyPad wrote?  (exit 1 if changed)
pypad embed lesson.pypad.py > question.html     # the HTML block for a Moodle question or web page
pypad answers responses.csv --out answers/       # split a Moodle quiz "Responses" download into one file per student
pypad verify template.pypad.py answers/*.pypad.py   # re-check them against the template (exit 1 if any are not clean)
pypad embed lesson.pypad.py --answer-format base64 --loader https://pypad.dev/v1/pypad-mdl-quiz.js

convert never overwrites without --force. check, convert and embed also accept an HTML page that holds a notebook (an embed, or a PyPad "web page" export).

Marking

An assessment that matters should be checked where the student cannot touch it. The widget stops mistakes in the student's browser, but the browser is the student's. pypad verify applies, on your side, the same rules the widget applies when it opens an answer (the template's policy, its locked cells, its answer cells and sections), and tells you for each answer what the student changed, added or removed, and what the rules would have put back:

answers/Student_Sam.pypad.py: clean (check value ok) - changed a1
answers/Other_Oz.pypad.py: NOT CLEAN (check value ok) - changed a1
    cell "i1" cannot be edited, and its text was put back

pypad answers turns a Moodle quiz Responses download (CSV) into those files, decoding stored answers.

In Python

import pypad

result = pypad.parse(open("lesson.pypad.py", encoding="utf-8").read())
result.integrity            # 'ok', 'changed' or 'absent'
result.warnings             # problems found while reading; a damaged file still opens
nb = result.notebook        # nb.config, nb.cells[i].id / .type / .source / .settings / .outputs

text = pypad.dumps(nb)                          # .pypad.py text, with its check value
ipynb = pypad.to_ipynb_text(nb, save_outputs="text")
nb2 = pypad.from_ipynb_text(open("lesson.ipynb", encoding="utf-8").read())
html = pypad.build_embed(text, answer_format="plain")

report = pypad.verify_answer(template_nb, answer_nb, integrity)   # report.clean, .changed_cells, .violations, ...

It matches the JavaScript implementation

This is a port of the reference implementation (packages/notebook in the PyPad repository). The same text produces the same notebook, the same file, the same Jupyter notebook and the same check value, including for emoji and odd characters. That is tested against a file of vectors that the JavaScript implementation generates (tests/vectors.json), so the two cannot drift apart unnoticed.

The format, in one screen

# %% [pypad-start] v1 sha=3f9a1c0d7b2e4a65

# %% [config] {"policy":"fixed","kernel":"skulpt"}

# %% [markdown] {"id":"k3j9a0xq","editable":false}
"""
Print the sum of 1 and 2.
"""

# %% [code] {"id":"p8w2m1zc"}
print(1 + 2)

# %% [pypad-end]

Code is code and everything else sits in triple-quoted strings, so the file is (nearly) valid Python and readable anywhere. The sha is a check value of the notebook's content: it notices an editor or a hand edit changing something, and ignores indentation and line endings. It is not a security measure. Reading is forgiving (Jupytext-style comment blocks, indented text, Windows line endings); writing has one form.

MIT licensed.

Metadata

Release files for pypad-notebook 0.2.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 pypad-notebook 0.2.0
File Size Uploaded Provenance
pypad_notebook-0.2.0.tar.gz 62.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pypad-notebook 0.2.0
File Interpreter ABI Platform
pypad_notebook-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 100.9 kB

Release files / pypad_notebook-0.2.0.tar.gz

Download URL pypad_notebook-0.2.0.tar.gz
Size 62.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9246f0fc377b3b6f1f5a3187ecd4ab3d420ad5c7d1ac003403389c28753acd0f
BLAKE2b-256 checksum
How to use checksums
a9de63b984af367e9020c4234c44332447d4ba133e2848e033fa32bd791dd957
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / pypad_notebook-0.2.0-py3-none-any.whl

Download URL pypad_notebook-0.2.0-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df9d7a4d96386f399edb2aa58e829ff081ea1f47f63443519b354522ad84dfb3
BLAKE2b-256 checksum
How to use checksums
23c72cd575d65f92604044121236c5ff27235d035981bb5ced0c0bd988a45e1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Security for pypad-notebook 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pypad_notebook-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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