Skip to main content

A description of your project

Project description

execnb

CI Deploy to GitHub Pages

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):

from execnb.nbio import *
from execnb.shell import *
from fastcore.utils 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 DEST] [--exc_stop] [--inject_code INJECT_CODE]
               [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX]
               [--verbose]
               src

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

positional arguments:
  src                        Notebook path to read from

optional arguments:
  -h, --help                 show this help message and exit
  --dest DEST                Notebook path to write to (default: )
  --exc_stop                 Stop on exceptions? (default: False)
  --inject_code INJECT_CODE  Code to inject into a cell
  --inject_path INJECT_PATH  Path to file containing code to inject into a cell
  --inject_idx INJECT_IDX    Cell to replace with `inject_code` (default: 0)
  --verbose                  Show stdout/stderr during execution (default: False)

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

execnb-0.1.18.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

execnb-0.1.18-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file execnb-0.1.18.tar.gz.

File metadata

  • Download URL: execnb-0.1.18.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for execnb-0.1.18.tar.gz
Algorithm Hash digest
SHA256 54cd96b1d14809ceedac28dfba92f9c16d14153cd15b944f7d6b3a8d8a424833
MD5 7c16deb9f631fcde5051fc454af6e592
BLAKE2b-256 7b4275dea9111731e7918eb62f3ab2d15b6c416a72ee62598e252537da3ebabd

See more details on using hashes here.

File details

Details for the file execnb-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: execnb-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for execnb-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 3d2083dfd14ac8489067019c044c848357d7390f9a22f438f8f3947b5aa9cc50
MD5 64d7022cd4b8c45908dd74a36b7d0363
BLAKE2b-256 722e1a091572fdeb08a1788647bf5f6e7c751da06f5433ef64e67d939b9c88bd

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