notebook parsing minimum DSL
Project description
nbdantic ◬
fully typed context-free grammar for jupyter notebooks. declare expected structure, validate against it.
install
uv add nbdantic
grammar
| production | rule | note |
|---|---|---|
| Notebook | Cell* Sequence Cell_terminal? | |
| Sequence | (Element …)+ | ε | empty=True allows ε |
| Element | Markdown | Code | Sequence | Choice | Maybe | |
| Markdown | cell<markdown> | terminal |
| Code | cell<code> | terminal |
| Choice | Element | Element | … | first match wins |
| Maybe | Element | ε |
grammar elements
type ParseElement = Markdown | Code | Sequence | Choice | Maybe
# Markdown and Code are self explanatory
# Sequence is None one or more elements (enabling nesting of structures/sequences)
# Choice lets you pick from a set of Elements (it could be arbitrary sets of nested pattenrs)
# Maybe allows for expressing Optiona<Element>
usage
import ast # for custom validation function
from nbdantic import Code, Markdown, Maybe, Sequence, JupyterNotebook
from nbdantic.validators import valid_python, not_empty, at_least
def only_imports(c):
tree = ast.parse(c)
if not all(
isinstance(n, (ast.Import, ast.ImportFrom, ast.alias, ast.Module)) for n in ast.walk(tree)
):
raise ValueError("code should only contain import statements")
class Paper(JupyterNotebook):
structure = Sequence("root", [
Markdown("title", validators=[not_empty]),
Code("imports", validators=[valid_python, only_imports]),
Maybe("abstract", Markdown("abstract_md")),
Sequence("sections", [
Markdown("heading"),
Code("body", validators=[valid_python]),
], validators=[at_least(2)], empty=True),
])
result = Paper.from_file("paper.ipynb").validate()
result.raise_if_failed()
result.cells_map
extra features
built-in validators
nbdantic.validators has some common checks, some of them are simple and example like, some of them may prove useful, like
ty_checkruff_checkline_warning
script runner
nbdantic.script_runner.UVScriptRunner spins up isolated uv environments for running code, linting, type checking, whatever you need. validators like ruff_check and ty_check use it under the hood.
from nbdantic.script_runner import UVScriptRunner
with UVScriptRunner(packages=["numpy>=1.24"], python_version="3.13") as runner:
result = runner.oneshot_python("import numpy; print(numpy.__version__)")
print(result.stdout)
notes
pep-508/440 parsing backed by uv-pep508 & uv-pep440 crates via pyo3. Thanks uv for everything.
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbdantic-0.1.0.tar.gz.
File metadata
- Download URL: nbdantic-0.1.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8256ceb930edd44781bf2f1c6979c6c6d7dedbdce1182b47828b27b3cdda605
|
|
| MD5 |
f7309ea8e9a5324a6b764545f902f0ab
|
|
| BLAKE2b-256 |
9cfafed290343645002d0b4749c476532e725a58a306e329c73084ab85bfe2ca
|
File details
Details for the file nbdantic-0.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.14t, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
399cfd6b0b3c2c5fbbeb19c33eeefad87df6d47cffd6171423061cb270be37af
|
|
| MD5 |
b9437ab9db78e92d821fe78ea6f7a853
|
|
| BLAKE2b-256 |
4a0992fe45e34eb9e64f0dff60d641122d4e290a9982c4cc38cc6bb769c00c42
|
File details
Details for the file nbdantic-0.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.14t, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a652e6eb2c8aeab82bbeca9665c8c0fdcbb3b013169658d2550c32844aa26c6
|
|
| MD5 |
c4fb4c4ff9c160e63c347cf835f93c91
|
|
| BLAKE2b-256 |
4b2b616498786fa6cd520f2a98695701d67f63190f0c1f0a5cbb2ee70d81239f
|
File details
Details for the file nbdantic-0.1.0-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4836769c409d03d598cd8a43085d518117e5a619425f6c30a099bcdcacb7310a
|
|
| MD5 |
6bdde704acb80b918f8ada1f76eef88b
|
|
| BLAKE2b-256 |
ca55ffe9a3f10a3740fe25ca6768f7e4f6c6e83dae4c59644a2043cb9fc874b7
|
File details
Details for the file nbdantic-0.1.0-cp314-cp314-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp314-cp314-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.14, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9860ace52689dcda105a05911a2e555d72087e319bdc566a7ca7fd1fdd78c5a8
|
|
| MD5 |
ea9f85897ec45a334665a2e372b314b8
|
|
| BLAKE2b-256 |
b30d015f512d149f994b2c6bfa893f82651017b04a37ce428dbba9bd7c7a86d8
|
File details
Details for the file nbdantic-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f4e0b8beae0d1e53510f5b4795faa8a583619d427cb56b82f02aa8769a55661
|
|
| MD5 |
930c4463a863bfda7bece0f280eb064e
|
|
| BLAKE2b-256 |
33177ad04688279b25b0e14225013a541d311edd145aa195f51766b1343b2dcd
|
File details
Details for the file nbdantic-0.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c9e00b99a60abc53e391ba5ca11edb78de8bf5b4f5b3b0c1f981b35f0512c73
|
|
| MD5 |
89b77cd32f0c014a212a38a3b1f8368f
|
|
| BLAKE2b-256 |
83ae89e82d6c1b25e2e295064e8867d6696c1a82a5258c1175e55bc06be6db9f
|
File details
Details for the file nbdantic-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a3ef204af42dcfb2de5cc01cff107796f1d7c186db05217457379c0eba26693
|
|
| MD5 |
2ed06f9dbb25852ead9b9574464f7d50
|
|
| BLAKE2b-256 |
bb141202eff25478c760080a0471ca7448b709fbcdab30b9b322244020bae174
|
File details
Details for the file nbdantic-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.14, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51902988ad8fdf72ac4361cd39dcd7cd1cc23bc9392533518e815f13e6628276
|
|
| MD5 |
0562a5bd2882ffce552fbbb75c520f88
|
|
| BLAKE2b-256 |
1ce2cad4059d0a73c712f71da84d4003d444ff289bf8e017154259948490c36b
|
File details
Details for the file nbdantic-0.1.0-cp313-cp313t-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp313-cp313t-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.13t, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b8e797aead811753e44871da76c1274f047e245c61fe74b5a1ca754d8028f28
|
|
| MD5 |
f51439ec2bea7de869f6234c4205667d
|
|
| BLAKE2b-256 |
81604c71f30595fed7b7a2bff99f0364e7393d1624963833ee77f420218ccbd1
|
File details
Details for the file nbdantic-0.1.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13t, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73bd501ebcdffe1bfda57bd01fc7c79e442b1d941f64b172d34cad670e70cb04
|
|
| MD5 |
5384bca126a9d124131eb7f6bacaa081
|
|
| BLAKE2b-256 |
b99118813aacf95d7785e7153ba171055280e477aa54eab932d7c0edcf0048df
|
File details
Details for the file nbdantic-0.1.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2a26e4e3e4659ae59362fd54a5e9197eb069cd1de75f359ad615f216fa4d03a
|
|
| MD5 |
c3150444b907cf9ea969566b32fe8e67
|
|
| BLAKE2b-256 |
3607ed9fad92f416fe726121dd26f60e1b09b8f20aba3c681617f79ed9c3055a
|
File details
Details for the file nbdantic-0.1.0-cp313-cp313-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp313-cp313-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f7c3894b5b11fc3f803ca7d2985de580f35215332d191bea8dd434b649da764
|
|
| MD5 |
b155c76c530f4905135cafa3a7e9ebd1
|
|
| BLAKE2b-256 |
0909c00ee788900d49c52081c3dec525bbecbdbcf82fbf145a3744e908397fd9
|
File details
Details for the file nbdantic-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14e66d27b5e207f07d27f90602d9d1c94790a2f52ae255a0b247efd4cbe0b435
|
|
| MD5 |
1e6d5348f856f99fe281ede0e884f98b
|
|
| BLAKE2b-256 |
1ccad644321cbbcbc4a4d8d95401fbe3ad95500be10ddac565bb12f6bdd5b886
|
File details
Details for the file nbdantic-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d3d9d78ad828c4232257a8393b6cacafeaee8a8df6857021f223de0b75c1842
|
|
| MD5 |
d8d9a70ff16a7f75779065447645d6a7
|
|
| BLAKE2b-256 |
2b7d0ebe4ee15b1d4f869b276648fc436a448ba34ad78f19b2584aadc71ef978
|
File details
Details for the file nbdantic-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6f0f230ea2eb99b17df749acc13d8516cb7b05445af362f70dedd9a31af108d
|
|
| MD5 |
9839a5e3bdb061757e2a32f720071ab7
|
|
| BLAKE2b-256 |
83e07ccf2a387b797a0459074ab132b2e707f350a16976ad4880707f596a201b
|
File details
Details for the file nbdantic-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl.
File metadata
- Download URL: nbdantic-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.13, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf3b57cc4f8d85b1c01fea9c4903946c5b2c74cde0bcaa6b8b0af00d6bad876b
|
|
| MD5 |
a9ed786781b378e0e7717a32895edad8
|
|
| BLAKE2b-256 |
442baca21bf6cd046d1ca08103c958c7f366df9e94b9a398058bd56b178f7fed
|