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

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.14.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

execnb-0.1.14-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: execnb-0.1.14.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for execnb-0.1.14.tar.gz
Algorithm Hash digest
SHA256 ba87e955809bd33318aa13314ff4df90b424bb4556741c2dcc90c7a28bc87ddd
MD5 82e42034bf5fdd38b42003e77d3c0b43
BLAKE2b-256 a51f56c875f092a7ec1e7715d352369944a7d80bc8744cd054e9ce3d25740f7d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: execnb-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for execnb-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 486065e0fa8a15c9668e1710f43aed3f73fd4fe1de15fd45e027aeea588c2936
MD5 074874c67e2e3ccd02465d55a3740229
BLAKE2b-256 b004cb12795bb98c806b165e494c25671329d8dc35ee6c1bb361acf26d47a553

See more details on using hashes here.

Supported by

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