Skip to main content

execnb

Install

Either:

pip install execnb

or if you use conda:

conda install -c fastai execnb

(You can replace conda with mamba in the line above if you have mamba installed.)

How to use

Use CaptureShell to run Jupyter code and capture notebook outputs, without running a Jupyter server (or even having it installed). The API is sync – each shell runs cells on its own private event loop in a background thread, so it works the same from a script, a notebook, or an async server, and cells may use top-level await:

from execnb.shell import *
from fastcore.utils import *
from fastcore.nbio import *
s = CaptureShell()
s.run('1+1')
[{'data': {'text/plain': ['2']},
  'metadata': {},
  'output_type': 'execute_result',
  'execution_count': 1}]

To execute a notebook and save it with outputs filled in, use CaptureShell.execute:

try:
    s.execute('../tests/clean.ipynb', 'tmp.ipynb')
    print(read_nb('tmp.ipynb').cells[1].outputs)
finally: Path('tmp.ipynb').unlink()
[{'name': 'stdout', 'output_type': 'stream', 'text': '1\n'}, {'data': {'text/plain': '2'}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}]

You can also execute notebooks from the command line with exec_nb:

!exec_nb --help
usage: exec_nb [-h] [--dest (str)] [--exc-stop] [--inject-code (str)]
               [--inject-path (str)] [--inject-idx (int)] [--verbose]
               [--cell-timeout (int)]
               src

Execute notebook from `src` and save with outputs to `dest`

positional arguments:
  src                   Notebook path to read from

options:
  -h, --help            show this help message and exit
  --dest (str)          Notebook path to write to (default: '')
  --exc-stop            Stop on exceptions? (default: False)
  --inject-code (str)   Code to inject into a cell
  --inject-path (str)   Path to file containing code to inject into a cell
  --inject-idx (int)    Cell to replace with `inject_code` (default: 0)
  --verbose             Show stdout/stderr during execution (default: False)
  --cell-timeout (int)  Seconds before each cell times out (None: no limit)

execnb 0.3.4

Metadata

Release files for execnb 0.3.4

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

Source distribution (sdist)

Source distribution for execnb 0.3.4
File Size Uploaded Provenance Actions
execnb-0.3.4.tar.gz 15.8 kB Without provenance Details for execnb-0.3.4.tar.gz

Built distribution (wheel)

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

Total release size: 30.5 kB

Release files / execnb-0.3.4.tar.gz

Download URL execnb-0.3.4.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dadb51fca0ce7976279c2290d7fe7e64b116ae5cfa9e6585972e3dea75996c0c
BLAKE2b-256 checksum
How to use checksums
07a0b55bfb4dab7e6377d2916c821a6b413b055d03f05b0ffaf4446e17afb9e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / execnb-0.3.4-py3-none-any.whl

Download URL execnb-0.3.4-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d35e280bc2e00e87893896c404a9cbc07ad29d89aca9da7d611976bc2c4ff117
BLAKE2b-256 checksum
How to use checksums
bee76d2f80df71ac75b3d0ac38834862e398d71dee2c022a89b60db6b273b8a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for execnb 0.3.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

0.3.4 This release

2 release files No 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