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 async, so await the run from a notebook or async code, or wrap it in asyncio.run at a sync entry point:
from execnb.shell import *
from fastcore.utils import *
from fastcore.nbio import *
s = CaptureShell()
await 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:
await 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)
Metadata
Release files for execnb 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| execnb-0.3.3.tar.gz | 15.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| execnb-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.5 kB
Release files / execnb-0.3.3.tar.gz
| Download URL | execnb-0.3.3.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d026b7e507e1acd13205d61ff4a0a5e6d0498ce3c395aefd87c5b4a0e1875aed
|
|
BLAKE2b-256 checksum How to use checksums |
960a157a22ca0728856bb654ecf7da49cc0398307edec292f45a11467d10a321
|
| 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.3-py3-none-any.whl
| Download URL | execnb-0.3.3-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f55c824a8f98c58b43bd107071c23bc873a70f298fce737d6b3bb85546c576e
|
|
BLAKE2b-256 checksum How to use checksums |
e0b2532b4335fd03d9213579de37352ff7db16fc8874b4b4a5d58977b6124d04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|