A CLI tool and pre-commit hook to verify Jupyter Notebook execution order.
Project description
nb-order-validator
A pre-commit hook and CLI tool to verify that Jupyter Notebook code cells have been executed in consecutive order.
Why nb-order-validator?
When working with Jupyter Notebooks in a collaborative environment or CI/CD pipeline, it's important to ensure that notebooks are executed in the correct order. This tool validates that all code cells have consecutive execution_count values (e.g., 1, 2, 3, 4...), helping you:
- Catch notebooks that were executed out of order
- Ensure reproducibility of notebook results
- Maintain code quality in team environments
- Integrate notebook validation into your CI/CD pipeline
Features
- Fast validation using streaming JSON parser (handles large notebooks efficiently)
- Pre-commit hook integration for automatic validation
- Parallel processing support for multiple notebooks
- Zero dependencies (only requires
ijson) - Comprehensive error reporting
Installation
As a pre-commit hook (Recommended)
Add to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/b-trout/nb-order-validator
rev: v0.1.0 # Use the latest version
hooks:
- id: check-nb-order
Then install the hook:
pre-commit install
As a standalone tool
pip install nb-order-validator
Usage
As a pre-commit hook
Once configured, the hook will automatically run when you commit .ipynb files:
git add notebook.ipynb
git commit -m "Add analysis notebook"
# The hook will validate execution order automatically
As a CLI tool
Validate a single notebook:
check-nb-order notebook.ipynb
Validate multiple notebooks:
check-nb-order notebook1.ipynb notebook2.ipynb notebook3.ipynb
Use with shell globbing:
check-nb-order notebooks/**/*.ipynb
Exit Codes
0: All notebooks have consecutive execution counts1: One or more notebooks have non-consecutive execution counts
Examples
Valid Notebook
A notebook with cells executed in order (1, 2, 3, 4...):
$ check-nb-order analysis.ipynb
# No output, exit code 0
Invalid Notebook
A notebook with cells executed out of order:
$ check-nb-order analysis.ipynb
❌ Incorrect execution order: analysis.ipynb
# Exit code 1
Multiple Files
$ check-nb-order notebook1.ipynb notebook2.ipynb notebook3.ipynb
❌ Incorrect execution order: notebook2.ipynb
# Exit code 1
How It Works
The tool checks the execution_count field in each code cell of your Jupyter Notebook:
- Extracts all
execution_countvalues from code cells - Ignores markdown and other non-code cells
- Allows trailing
nullexecution counts (unexecuted cells at the end) - Verifies that remaining counts form a consecutive sequence
Valid Sequences
[1, 2, 3, 4]- Standard consecutive order[5, 6, 7, 8]- Consecutive starting from any number[1, 2, 3, null]- Trailing unexecuted cell is allowed[]- Empty notebook is valid
Invalid Sequences
[1, 3, 4]- Missing execution count (2)[1, 2, 2, 3]- Duplicate execution count[1, null, 3]- Unexecuted cell in the middle[3, 2, 1]- Reversed order
Requirements
- Python 3.10 or higher
ijson >= 3.4.0.post0
License
MIT License - see LICENSE file for details.
Repository
GitHub: https://github.com/b-trout/nb-order-validator
Author
b-trout (yuuta.masubuti@gmail.com)
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 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 nb_order_validator-0.1.1.tar.gz.
File metadata
- Download URL: nb_order_validator-0.1.1.tar.gz
- Upload date:
- Size: 60.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
074fc744f5be3f4f685663a188b9f8405b40f6a0ea184c5107ee1c894424f074
|
|
| MD5 |
c0b0f4cd5bf6bc12dacd2da901e39aab
|
|
| BLAKE2b-256 |
a2cc10f6cb6a4465b4c5ebaeb9aac2123c93864e9b4ba421439eeea9d58a7d86
|
Provenance
The following attestation bundles were made for nb_order_validator-0.1.1.tar.gz:
Publisher:
release.yml on b-trout/nb-order-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nb_order_validator-0.1.1.tar.gz -
Subject digest:
074fc744f5be3f4f685663a188b9f8405b40f6a0ea184c5107ee1c894424f074 - Sigstore transparency entry: 814262060
- Sigstore integration time:
-
Permalink:
b-trout/nb-order-validator@25011b6bf4eccfd6cad2be6b969cde0ade2c28c3 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/b-trout
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@25011b6bf4eccfd6cad2be6b969cde0ade2c28c3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nb_order_validator-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nb_order_validator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec5dd9bb3d966459813bb18a94b3f945cfebc1f310a2b53c537fa064fb4ada02
|
|
| MD5 |
962a03adbec4b25c2ead36bca975b6eb
|
|
| BLAKE2b-256 |
0ff60c200793e6f684538ed94d2bddfa3d3733f90006fcf8c5151690fc5ef918
|
Provenance
The following attestation bundles were made for nb_order_validator-0.1.1-py3-none-any.whl:
Publisher:
release.yml on b-trout/nb-order-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nb_order_validator-0.1.1-py3-none-any.whl -
Subject digest:
ec5dd9bb3d966459813bb18a94b3f945cfebc1f310a2b53c537fa064fb4ada02 - Sigstore transparency entry: 814262061
- Sigstore integration time:
-
Permalink:
b-trout/nb-order-validator@25011b6bf4eccfd6cad2be6b969cde0ade2c28c3 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/b-trout
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@25011b6bf4eccfd6cad2be6b969cde0ade2c28c3 -
Trigger Event:
release
-
Statement type: