Skip to main content

Plain .py files as notebooks

Project description

nobook

Plain .py files as notebooks. No .ipynb files ever.

Write Python with # @block=name markers. Each block becomes a Jupyter cell. The .py file is the notebook.

File format

# @block=setup
import math
x = 42

# @block=compute
result = math.sqrt(x)
print(f"sqrt({x}) = {result:.4f}")

A block starts at # @block=name and runs until the next # @block= or end of file. That's it.

Quick start

# 1. Create a .py file with block markers
cat > demo.py << 'EOF'
# @block=hello
print("hello from nobook")

# @block=math
import math
print(f"pi = {math.pi:.4f}")
EOF

# 2. Launch Jupyter (no install needed)
uvx nobook

Jupyter opens. Right-click demo.py in the file browser and select Open as Nobook. It renders as a notebook with two cells (hello and math). Run them, edit them, save -- the file stays .py.

As a project dependency

uv add nobook
uv run nobook

Opening .py files as notebooks

In JupyterLab / Jupyter Notebook, right-click any .py file and select Open as Nobook:

Right-click a .py file and select "Open as Nobook"

.py files containing # @block= markers will also auto-open as notebooks when double-clicked.

CLI commands

Launch Jupyter

uv run nobook           # launches Jupyter Notebook (default)
uv run nobook lab       # launches JupyterLab
uv run nobook jupyter   # same as default, launches Jupyter Notebook

All launch commands accept extra arguments that are passed through to Jupyter:

uv run nobook --port=9999 --no-browser
uv run nobook lab --port=9999

Run blocks without Jupyter

uv run nobook run example.py                 # execute all blocks, write example.out.py
uv run nobook run example.py --block=setup   # run up to and including "setup"
uv run nobook list example.py                # print block names

Output goes to .out.py with results inlined as comments:

# @block=setup
import math
x = 42
# >>>

# @block=compute
result = math.sqrt(x)
print(f"sqrt({x}) = {result:.4f}")
# >>> sqrt(42) = 6.4807

Errors show as # !!! ... lines. Since output and errors are plain comments, .out.py files are valid Python -- you can run them directly with python example.out.py.

See examples/ for sample input and output files.

Manual launch (without the CLI wrapper)

uv run jupyter notebook --ServerApp.contents_manager_class=nobook.jupyter.contentsmanager.NobookContentsManager

Or for JupyterLab:

uv run jupyter lab --ServerApp.contents_manager_class=nobook.jupyter.contentsmanager.NobookContentsManager

How it works

Jupyter UI (standard, unmodified)
        |
IPython Kernel (standard, unmodified)
        |
NobookContentsManager          <-- intercepts file I/O
        |
.py files with # @block markers

The NobookContentsManager subclasses Jupyter's LargeFileManager. On get(), it parses # @block= markers and returns a notebook model (blocks as code cells). On save(), it converts the notebook model back to .py format. The kernel and UI are completely stock.

.py files without # @block= markers are served normally (as plain text files).

JupyterLab extension

Nobook includes a JupyterLab extension that adds:

  • Launcher card -- click "Nobook" in the launcher to create a new .py notebook
  • "Open as Nobook" context menu -- right-click any .py file to open it as a notebook
  • Block name labels -- editable labels on each cell showing the @block name

The extension is bundled with the package and installs automatically.

Development

To test nobook from any project without installing it:

uv run --project <path-to-nobook> python -m nobook

Full development install

git clone <repo-url> && cd nobook
uv sync
jlpm install && jlpm build
uv run jupyter labextension develop . --overwrite

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

nobook-0.0.2.tar.gz (204.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nobook-0.0.2-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file nobook-0.0.2.tar.gz.

File metadata

  • Download URL: nobook-0.0.2.tar.gz
  • Upload date:
  • Size: 204.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.5 HTTPX/0.28.1

File hashes

Hashes for nobook-0.0.2.tar.gz
Algorithm Hash digest
SHA256 558f1aadf261052c3d00e7bc738f7be941aeed8f6c62620a87553969bc3fc0d5
MD5 0bc3c67a7ba0e2c8fd4c7df2653a6ecc
BLAKE2b-256 1dced4946efa315a28ea03ef96da507ee4d175d48cb6b1cb1bdb3742b608350d

See more details on using hashes here.

File details

Details for the file nobook-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: nobook-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.5 HTTPX/0.28.1

File hashes

Hashes for nobook-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30e95e84ba191c982c4feba42f6ee7f795cf0a19a9186f4146d596d72b68b5f0
MD5 4ad702b95d2fb4d426145a2c68874479
BLAKE2b-256 907549a4ff5bbe7750e262f2d5b8b5abf86e6688f6f20070829d667fd3c20851

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page