Skip to main content

nb-order-validator

A pre-commit hook and CLI tool to verify that Jupyter Notebook code cells have been executed in consecutive order.

PyPI version Python Support License: MIT

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

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 counts
  • 1: 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:

  1. Extracts all execution_count values from code cells
  2. Ignores markdown and other non-code cells
  3. Allows trailing null execution counts (unexecuted cells at the end)
  4. Verifies that remaining counts form a consecutive sequence

Valid Sequences

  • [1, 2, 3, 4] - Standard consecutive order from 1
  • [1, 2, 3, null] - Trailing unexecuted cell is allowed
  • [] - Empty notebook is valid

Invalid Sequences

  • [1, 3, 4] - Missing execution count (2)
  • [2, 3, 4] - Consecutive order but not start from 1
  • [3, 1, 2] - Not consecutive order
  • [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)

Metadata

Release files for nb-order-validator 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nb-order-validator 0.1.2
File Size Uploaded Provenance Actions
nb_order_validator-0.1.2.tar.gz 60.6 kB With provenance Details for nb_order_validator-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nb-order-validator 0.1.2
File Interpreter ABI Platform Actions
nb_order_validator-0.1.2-py3-none-any.whl Python 3 none any Details for nb_order_validator-0.1.2-py3-none-any.whl

Total release size: 67.3 kB

Release files / nb_order_validator-0.1.2.tar.gz

Download URL nb_order_validator-0.1.2.tar.gz
Size 60.6 kB
Tags Source
SHA-256 checksum
How to use checksums
691bfc833d41a3ce7754d91387ecc402413527079805da92646b0bc544486085
BLAKE2b-256 checksum
How to use checksums
cf1e49f7358bef33fc61c42d6615a7eb3d498291ec8e18728ee242bffd257385
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 28, 2026.

Transparency log

Release files / nb_order_validator-0.1.2-py3-none-any.whl

Download URL nb_order_validator-0.1.2-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edcc3878b9313f5a3d8a193e63cdcc0eeca1bd32c46766ad39c75a0ff86eafb5
BLAKE2b-256 checksum
How to use checksums
bb4c120b90db31942a8386aed6e2131fecb43e65485b7dcced8ff182cc227c74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 28, 2026.

Transparency log

Security for nb-order-validator 0.1.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nb_order_validator-0.1.2.tar.gz

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 Feb 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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