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.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': None}]

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': None, '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

options:
  -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.2.5.tar.gz (14.3 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.2.5-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for execnb-0.2.5.tar.gz
Algorithm Hash digest
SHA256 2e9688c9eaea613611abeb62ad98afd51a8cce786ec53d1c244037ecdc33c2cb
MD5 b5f5db9aedb3417e129a1b562bfde3a3
BLAKE2b-256 33cf80b9b1eab1c923897a5cf3c7a99cb7e65865004955eb0b01a26ff1db63c4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for execnb-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 806fec8aeca81166b80cc954fda6e8c912d447271727309268c7c3802cccb837
MD5 2e5424f67ee8b956205d245d427d8bd7
BLAKE2b-256 5c1bfb174871d7b70f2738e16e3eaa214766da5e82b48f6f94d4b318ed9cf1fe

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