nbapproval
Notebook-friendly approval testing for Python and Jupyter.
nbapproval lets you compare actual notebook outputs to approved values,
store approvals in a separate approvals notebook, and fail CI runs when
approvals are missing or mismatched.
Install
pip install nbapproval
Quick Start
from nbapproval import approval_test
approval_test(
"Simple approval check",
{"value": 42},
)
approval_test.assert_all_approved()
API (Terse-First)
Primary call supports concise notebook usage:
approval_test(description, actual, sort_by=None)
Also supported:
idalias fortest_iddescalias fordescription- keyword form:
actual=... - automatic
test_idderivation fromdescriptionwhen omitted - pandas DataFrame values as
actual(auto-converted to stable records)
Examples:
# Explicit id + keyword style
approval_test(
id="known_holiday_checkpoints_match_expected_names_for_specific_dates",
desc="Known holiday checkpoints match expected names for specific dates.",
actual=approval_test.to_iso_records(actual_df),
sort_by=["Date", "Expected"],
)
# Terse positional style (id auto-derived from description)
approval_test(
"Known holiday checkpoints match expected names for specific dates.",
actual_df,
sort_by=["Date", "Expected"],
)
approval_test.from_dataframe(...) remains available, but is optional now because
the main call handles DataFrames directly.
Runtime Status
You can inspect the current approval run state directly:
approval_test.status_report()
approval_test.approvals_notebook_path
status_report()returns totals and per-test statuses for the current session.approvals_notebook_pathreturns the resolved approvals notebook path.
approval_test.assert_all_approved() prints a summary and approvals notebook path,
then raises if any test is not Approved.
Notebook Magics
The package registers two IPython magics for concise notebook tests:
%approvefor line-style checks%%approvefor cell-style checks
Examples:
# line magic with expression only
%approve bool(df["Date"].is_monotonic_increasing)
# line magic with options + expression (use :: separator)
%approve --id dates_are_sorted --desc "Dates are sorted" :: bool(df["Date"].is_monotonic_increasing)
# cell magic with a code block; last expression becomes approved value
%%approve --desc "Federal holidays for 2026" --sort-by "['Date', 'Holiday']"
df.loc[df["Year"] == 2026, ["Date", "Holiday"]]
Notes:
- In
%approve, when options are present, put::before the expression. - In
%%approve, full code blocks are supported; setup statements are allowed, and the last expression is used asactual.
Testing
Run tests with:
pip install -e .[dev]
pytest -q
Notes
- Stable and unique
test_idvalues are required. - For deterministic CI runs, configure an explicit approvals notebook path.
- Works well with Papermill-driven notebook execution.
License
Apache License 2.0. See LICENSE.
Metadata
Release files for nbapproval 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nbapproval-0.4.0.tar.gz | 21.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nbapproval-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.1 kB
Release files / nbapproval-0.4.0.tar.gz
| Download URL | nbapproval-0.4.0.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41926a0d21ba6d3cb88a398759391f263931d62002d0299dd84d00c44f818ed8
|
|
BLAKE2b-256 checksum How to use checksums |
8bcd1821039448d496a9c75d16e5b3eabeca1009dd1ffe7f8c3381e054ce42e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 21, 2026.
Transparency logRelease files / nbapproval-0.4.0-py3-none-any.whl
| Download URL | nbapproval-0.4.0-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30c0da95606de462391c1d855f5c8fec53e59d72cf4cc8002d74e5f98836097a
|
|
BLAKE2b-256 checksum How to use checksums |
f13ebb3c1c420de7dbc77ef828bd0a3a9670a0c0449c1dcdbbf7d7caf37a4861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 21, 2026.
Transparency log