Notebook-friendly approval testing for Python and Jupyter
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 nbapproval-0.4.0.tar.gz.
File metadata
- Download URL: nbapproval-0.4.0.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41926a0d21ba6d3cb88a398759391f263931d62002d0299dd84d00c44f818ed8
|
|
| MD5 |
eb05188199bf978f083f1f0206eb8bba
|
|
| BLAKE2b-256 |
8bcd1821039448d496a9c75d16e5b3eabeca1009dd1ffe7f8c3381e054ce42e7
|
Provenance
The following attestation bundles were made for nbapproval-0.4.0.tar.gz:
Publisher:
publish.yml on wiki3-ai/nbapproval
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbapproval-0.4.0.tar.gz -
Subject digest:
41926a0d21ba6d3cb88a398759391f263931d62002d0299dd84d00c44f818ed8 - Sigstore transparency entry: 1591826038
- Sigstore integration time:
-
Permalink:
wiki3-ai/nbapproval@865a74f36b7ed116edc9399002dc86ad34cc4c51 -
Branch / Tag:
refs/tags/0.4.0 - Owner: https://github.com/wiki3-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@865a74f36b7ed116edc9399002dc86ad34cc4c51 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nbapproval-0.4.0-py3-none-any.whl.
File metadata
- Download URL: nbapproval-0.4.0-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30c0da95606de462391c1d855f5c8fec53e59d72cf4cc8002d74e5f98836097a
|
|
| MD5 |
48f605f8d92c5c2fa0206cd45a1498a9
|
|
| BLAKE2b-256 |
f13ebb3c1c420de7dbc77ef828bd0a3a9670a0c0449c1dcdbbf7d7caf37a4861
|
Provenance
The following attestation bundles were made for nbapproval-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on wiki3-ai/nbapproval
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbapproval-0.4.0-py3-none-any.whl -
Subject digest:
30c0da95606de462391c1d855f5c8fec53e59d72cf4cc8002d74e5f98836097a - Sigstore transparency entry: 1591826069
- Sigstore integration time:
-
Permalink:
wiki3-ai/nbapproval@865a74f36b7ed116edc9399002dc86ad34cc4c51 -
Branch / Tag:
refs/tags/0.4.0 - Owner: https://github.com/wiki3-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@865a74f36b7ed116edc9399002dc86ad34cc4c51 -
Trigger Event:
release
-
Statement type: