Skip to main content

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_check
  • ruff_check
  • line_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.

Metadata

Release files for nbdantic 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 nbdantic 0.1.0
File Size Uploaded
nbdantic-0.1.0.tar.gz 27.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for nbdantic 0.1.0
File
nbdantic-0.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64 Details
nbdantic-0.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 Details
nbdantic-0.1.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
nbdantic-0.1.0-cp314-cp314-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 Linux musl 1.2+ x86-64 Details
nbdantic-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
nbdantic-0.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64 Details
nbdantic-0.1.0-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
nbdantic-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.12+ x86-64 Details
nbdantic-0.1.0-cp313-cp313t-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 free-threading Linux musl 1.2+ x86-64 Details
nbdantic-0.1.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ ARM64 Details
nbdantic-0.1.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
nbdantic-0.1.0-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details
nbdantic-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
nbdantic-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details
nbdantic-0.1.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
nbdantic-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details

Total release size: 20.9 MB

Release files / nbdantic-0.1.0.tar.gz

Download URL nbdantic-0.1.0.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e8256ceb930edd44781bf2f1c6979c6c6d7dedbdce1182b47828b27b3cdda605
BLAKE2b-256 checksum
How to use checksums
9cfafed290343645002d0b4749c476532e725a58a306e329c73084ab85bfe2ca
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl

Download URL nbdantic-0.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Size 1.6 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
399cfd6b0b3c2c5fbbeb19c33eeefad87df6d47cffd6171423061cb270be37af
BLAKE2b-256 checksum
How to use checksums
4a0992fe45e34eb9e64f0dff60d641122d4e290a9982c4cc38cc6bb769c00c42
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL nbdantic-0.1.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.3 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
5a652e6eb2c8aeab82bbeca9665c8c0fdcbb3b013169658d2550c32844aa26c6
BLAKE2b-256 checksum
How to use checksums
4b2b616498786fa6cd520f2a98695701d67f63190f0c1f0a5cbb2ee70d81239f
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp314-cp314-win_amd64.whl

Download URL nbdantic-0.1.0-cp314-cp314-win_amd64.whl
Size 1.0 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
4836769c409d03d598cd8a43085d518117e5a619425f6c30a099bcdcacb7310a
BLAKE2b-256 checksum
How to use checksums
ca55ffe9a3f10a3740fe25ca6768f7e4f6c6e83dae4c59644a2043cb9fc874b7
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp314-cp314-musllinux_1_2_x86_64.whl

Download URL nbdantic-0.1.0-cp314-cp314-musllinux_1_2_x86_64.whl
Size 1.6 MB
Tags CPython 3.14 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
9860ace52689dcda105a05911a2e555d72087e319bdc566a7ca7fd1fdd78c5a8
BLAKE2b-256 checksum
How to use checksums
b30d015f512d149f994b2c6bfa893f82651017b04a37ce428dbba9bd7c7a86d8
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL nbdantic-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.3 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5f4e0b8beae0d1e53510f5b4795faa8a583619d427cb56b82f02aa8769a55661
BLAKE2b-256 checksum
How to use checksums
33177ad04688279b25b0e14225013a541d311edd145aa195f51766b1343b2dcd
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL nbdantic-0.1.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.3 MB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
1c9e00b99a60abc53e391ba5ca11edb78de8bf5b4f5b3b0c1f981b35f0512c73
BLAKE2b-256 checksum
How to use checksums
83ae89e82d6c1b25e2e295064e8867d6696c1a82a5258c1175e55bc06be6db9f
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL nbdantic-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Size 1.2 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0a3ef204af42dcfb2de5cc01cff107796f1d7c186db05217457379c0eba26693
BLAKE2b-256 checksum
How to use checksums
bb141202eff25478c760080a0471ca7448b709fbcdab30b9b322244020bae174
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl

Download URL nbdantic-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl
Size 1.2 MB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
51902988ad8fdf72ac4361cd39dcd7cd1cc23bc9392533518e815f13e6628276
BLAKE2b-256 checksum
How to use checksums
1ce2cad4059d0a73c712f71da84d4003d444ff289bf8e017154259948490c36b
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp313-cp313t-musllinux_1_2_x86_64.whl

Download URL nbdantic-0.1.0-cp313-cp313t-musllinux_1_2_x86_64.whl
Size 1.6 MB
Tags CPython 3.13 CPython 3.13 free-threading Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
7b8e797aead811753e44871da76c1274f047e245c61fe74b5a1ca754d8028f28
BLAKE2b-256 checksum
How to use checksums
81604c71f30595fed7b7a2bff99f0364e7393d1624963833ee77f420218ccbd1
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL nbdantic-0.1.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.3 MB
Tags CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
73bd501ebcdffe1bfda57bd01fc7c79e442b1d941f64b172d34cad670e70cb04
BLAKE2b-256 checksum
How to use checksums
b99118813aacf95d7785e7153ba171055280e477aa54eab932d7c0edcf0048df
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp313-cp313-win_amd64.whl

Download URL nbdantic-0.1.0-cp313-cp313-win_amd64.whl
Size 1.0 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
c2a26e4e3e4659ae59362fd54a5e9197eb069cd1de75f359ad615f216fa4d03a
BLAKE2b-256 checksum
How to use checksums
3607ed9fad92f416fe726121dd26f60e1b09b8f20aba3c681617f79ed9c3055a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL nbdantic-0.1.0-cp313-cp313-musllinux_1_2_x86_64.whl
Size 1.6 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
4f7c3894b5b11fc3f803ca7d2985de580f35215332d191bea8dd434b649da764
BLAKE2b-256 checksum
How to use checksums
0909c00ee788900d49c52081c3dec525bbecbdbcf82fbf145a3744e908397fd9
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL nbdantic-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
14e66d27b5e207f07d27f90602d9d1c94790a2f52ae255a0b247efd4cbe0b435
BLAKE2b-256 checksum
How to use checksums
1ccad644321cbbcbc4a4d8d95401fbe3ad95500be10ddac565bb12f6bdd5b886
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL nbdantic-0.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.3 MB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
7d3d9d78ad828c4232257a8393b6cacafeaee8a8df6857021f223de0b75c1842
BLAKE2b-256 checksum
How to use checksums
2b7d0ebe4ee15b1d4f869b276648fc436a448ba34ad78f19b2584aadc71ef978
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL nbdantic-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Size 1.2 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a6f0f230ea2eb99b17df749acc13d8516cb7b05445af362f70dedd9a31af108d
BLAKE2b-256 checksum
How to use checksums
83e07ccf2a387b797a0459074ab132b2e707f350a16976ad4880707f596a201b
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / nbdantic-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl

Download URL nbdantic-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl
Size 1.2 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
bf3b57cc4f8d85b1c01fea9c4903946c5b2c74cde0bcaa6b8b0af00d6bad876b
BLAKE2b-256 checksum
How to use checksums
442baca21bf6cd046d1ca08103c958c7f366df9e94b9a398058bd56b178f7fed
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.1.0 This release

17 release files

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