Skip to main content

nblite

Notebook-driven Python development made simple.

nblite is a tool for developing Python packages using Jupyter notebooks, and/or plaintext notebooks (e.g. percent format .pct.py files) as the source of truth. Write your code in notebooks, add export directives, and nblite generates clean Python modules automatically.

Note: nblite was inspired by the excellent nbdev, with some adjustments to make it more lightweight and quality-of-life additions. Full credit of the concept and implementation of notebook-driven development using Jupyter notebooks should go to the creators of nbdev.

Features

  • Notebook-first development: Write code in Jupyter notebooks with full interactivity
  • Automatic module generation: Export marked cells to Python modules
  • Multiple formats: Support for .ipynb, percent-style .pct.py, and standard .py modules
  • Smart execution: Fill notebook outputs with parallel execution and change detection
  • Git integration: Pre-commit hooks for auto-cleaning and validation
  • Documentation generation: Build docs with MkDocs, Jupyter Book, or Quarto
  • Flexible pipelines: Define custom export pipelines between code locations

Installation

pip install nblite

Quick Start

1. Initialize a project

mkdir myproject && cd myproject
nbl init --name mylib

This creates:

myproject/
├── nblite.toml     # Configuration file
├── nbs/            # Notebooks directory
└── mylib/          # Python package
    └── __init__.py

2. Create a notebook

nbl new nbs/core.ipynb --title "Core Module"

3. Add code with export directives

In your notebook, mark cells for export:

#|default_exp core

#|export
def greet(name: str) -> str:
    """Return a greeting message."""
    return f"Hello, {name}!"

#|export
class Calculator:
    """A simple calculator."""

    def add(self, a: int, b: int) -> int:
        return a + b

4. Export to Python modules

nbl export

This generates mylib/core.py:

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/core.ipynb

__all__ = ['greet', 'Calculator']

def greet(name: str) -> str:
    """Return a greeting message."""
    return f"Hello, {name}!"

class Calculator:
    """A simple calculator."""

    def add(self, a: int, b: int) -> int:
        return a + b

5. Fill notebook outputs

nbl fill

Executes all notebooks and saves their outputs. Uses smart change detection to skip unchanged notebooks.

Configuration

nblite is configured via nblite.toml:

# Export pipeline: notebooks -> modules
export_pipeline = "nbs -> lib"

# Code locations
[cl.nbs]
path = "nbs"
format = "ipynb"

[cl.lib]
path = "mylib"
format = "module"

# Git hooks (optional)
[git]
auto_clean = true
auto_export = true

# Notebook cleaning (optional)
[clean]
remove_outputs = false
remove_execution_counts = false

See the Configuration Guide for all options.

Export Directives

Control what gets exported with special comments:

Directive Description
#|default_exp module_name Set the default export module
#|export Export this cell to the default module
#|exporti Export as internal (not in __all__)
#|export_to module_name Export to a specific module
#|hide Hide cell from documentation
#|eval: false Skip cell during execution

See the Directives Reference for all directives.

CLI Commands

Command Description
nbl init Initialize a new project
nbl new Create a new notebook
nbl export Run the export pipeline
nbl fill Execute notebooks and fill outputs
nbl test Test notebooks execute without errors
nbl clean Clean notebooks (remove outputs/metadata)
nbl convert Convert between notebook formats
nbl from-module Convert Python modules to notebooks
nbl prepare Run export, clean, fill, and readme
nbl render-docs Generate documentation
nbl preview-docs Preview documentation
nbl info Show project information
nbl list List files in code locations
nbl install-hooks Install git hooks
nbl validate Validate git staging state

Use nbl <command> --help for detailed options.

See the CLI Reference for complete documentation.

Multi-Stage Pipelines

Define complex export pipelines:

# notebooks -> percent scripts -> modules
export_pipeline = """
nbs -> pcts
pcts -> lib
"""

[cl.nbs]
path = "nbs"
format = "ipynb"

[cl.pcts]
path = "pcts"
format = "percent"

[cl.lib]
path = "mylib"
format = "module"

This creates an intermediate representation in percent format, useful for:

  • Code review (percent files are plain Python)
  • Debugging export issues
  • Version control of notebook content

Git Integration

Install git hooks for automatic cleaning and export:

nbl install-hooks

The pre-commit hook will:

  1. Clean notebooks (remove outputs if configured)
  2. Run the export pipeline
  3. Validate staging state

Configure in nblite.toml:

[git]
auto_clean = true      # Clean notebooks before commit
auto_export = true     # Run export on commit
validate_staging = true # Warn about staging issues

Documentation Generation

Generate documentation from notebooks:

# Build documentation
nbl render-docs

# Preview with live reload
nbl preview-docs

Supported generators:

  • MkDocs (default): pip install mkdocs mkdocs-material mkdocs-jupyter
  • Jupyter Book: pip install jupyter-book
  • Quarto: Install from https://quarto.org/

Configure in nblite.toml:

docs_cl = "nbs"           # Code location to document
docs_title = "My Project" # Documentation title
docs_generator = "mkdocs" # Generator to use

[docs]
output_folder = "_docs"

Notebook Execution

Fill notebooks with outputs:

# Execute all notebooks
nbl fill

# Execute specific notebooks
nbl fill nbs/core.ipynb nbs/utils.ipynb

# Parallel execution
nbl fill --workers 8

# Test without saving (dry run)
nbl test

Control execution with directives:

#|eval: false
# This cell is skipped during execution
expensive_computation()

#|skip_evals
# All following cells are skipped
...

#|skip_evals_stop
# Execution resumes here

Converting Existing Code

Convert Python modules to notebooks:

# Single file
nbl from-module utils.py nbs/utils.ipynb

# Entire directory
nbl from-module src/ nbs/ --recursive

Project Structure

A typical nblite project:

myproject/
├── nblite.toml          # Configuration
├── nbs/                 # Source notebooks
│   ├── 00_index.ipynb
│   ├── 01_core.ipynb
│   └── 02_utils.ipynb
├── mylib/               # Generated Python package
│   ├── __init__.py
│   ├── core.py
│   └── utils.py
├── _docs/               # Generated documentation
└── README.md            # Generated from notebook

Documentation

Philosophy

nblite follows the literate programming philosophy: code and documentation live together. Notebooks are the source of truth, and Python modules are generated artifacts.

Key principles:

  1. Notebooks first: Write and test code interactively
  2. Explicit exports: Only marked cells become part of your library
  3. Clean separation: Keep exploration separate from production code
  4. Reproducibility: Fill outputs to ensure notebooks run correctly

Contributing

Contributions are welcome! Please see our contributing guidelines.

License

MIT License - see LICENSE file for details.

Acknowledgments

nblite is inspired by nbdev from fast.ai, reimagined as a lightweight, focused tool for notebook-driven development.

Metadata

Release files for nblite 1.2.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 nblite 1.2.2
File Size Uploaded Provenance Actions
nblite-1.2.2.tar.gz 326.7 kB With provenance Details for nblite-1.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nblite 1.2.2
File Interpreter ABI Platform Actions
nblite-1.2.2-py3-none-any.whl Python 3 none any Details for nblite-1.2.2-py3-none-any.whl

Total release size: 432.4 kB

Release files / nblite-1.2.2.tar.gz

Download URL nblite-1.2.2.tar.gz
Size 326.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4b9840ac36bf1c6ed12ff4f8a5c701b2353bece164856671cd7f8deaad4a2a2c
BLAKE2b-256 checksum
How to use checksums
03072bf2266ffb05a44e429ace5240a2006c88838955f76bfd56d3853ea57f6b
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 Jun 20, 2026.

Transparency log

Release files / nblite-1.2.2-py3-none-any.whl

Download URL nblite-1.2.2-py3-none-any.whl
Size 105.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc6c9596ecfa022269cdd66b05ffa774e956277b456c35aaffa0fbc8fb5b382c
BLAKE2b-256 checksum
How to use checksums
952f1b0723f563deb0cf08e186cc0de036e96e0f12273e89b16e068117c994c2
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 Jun 20, 2026.

Transparency log

Security for nblite 1.2.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nblite-1.2.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 Jun 20, 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.

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files Full provenance

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