# execnb
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
[![CI](https://github.com/fastai/execnb/actions/workflows/test.yaml/badge.svg)](https://github.com/fastai/execnb/actions/workflows/test.yaml)
[![Deploy to GitHub
Pages](https://github.com/fastai/execnb/actions/workflows/deploy.yaml/badge.svg)](https://github.com/fastai/execnb/actions/workflows/deploy.yaml)
## 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`](https://fastai.github.io/execnb/shell.html#captureshell)
to run Jupyter code and capture notebook outputs, without running a
Jupyter server (or even having it installed):
``` python
from execnb.nbio import *
from execnb.shell import *
from fastcore.utils import *
```
``` python
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`](https://fastai.github.io/execnb/shell.html#captureshell.execute):
``` python
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`](https://fastai.github.io/execnb/shell.html#exec_nb):
``` python
!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)
Raw data
{
"_id": null,
"home_page": "https://github.com/fastai/execnb/",
"name": "execnb",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "some keywords",
"author": "Jeremy Howard",
"author_email": "j@fast.ai",
"download_url": "https://files.pythonhosted.org/packages/99/22/1bcfa6ebc6b6db385c5b32bee1871d95fdbd29c2d47685546414bdcd60bc/execnb-0.1.8.tar.gz",
"platform": null,
"description": "# execnb\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n[![CI](https://github.com/fastai/execnb/actions/workflows/test.yaml/badge.svg)](https://github.com/fastai/execnb/actions/workflows/test.yaml)\n[![Deploy to GitHub\nPages](https://github.com/fastai/execnb/actions/workflows/deploy.yaml/badge.svg)](https://github.com/fastai/execnb/actions/workflows/deploy.yaml)\n\n## Install\n\nEither:\n\n pip install execnb\n\nor if you use conda:\n\n conda install -c fastai execnb\n\n(You can replace `conda` with `mamba` in the line above if you have\nmamba installed.)\n\n## How to use\n\nUse\n[`CaptureShell`](https://fastai.github.io/execnb/shell.html#captureshell)\nto run Jupyter code and capture notebook outputs, without running a\nJupyter server (or even having it installed):\n\n``` python\nfrom execnb.nbio import *\nfrom execnb.shell import *\nfrom fastcore.utils import *\n```\n\n``` python\ns = CaptureShell()\ns.run('1+1')\n```\n\n [{'data': {'text/plain': ['2']},\n 'metadata': {},\n 'output_type': 'execute_result',\n 'execution_count': 1}]\n\nTo execute a notebook and save it with outputs filled in, use\n[`CaptureShell.execute`](https://fastai.github.io/execnb/shell.html#captureshell.execute):\n\n``` python\ntry:\n s.execute('../tests/clean.ipynb', 'tmp.ipynb')\n print(read_nb('tmp.ipynb').cells[1].outputs)\nfinally: Path('tmp.ipynb').unlink()\n```\n\n [{'name': 'stdout', 'output_type': 'stream', 'text': ['1\\n']}, {'data': {'text/plain': ['2']}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}]\n\nYou can also execute notebooks from the command line with\n[`exec_nb`](https://fastai.github.io/execnb/shell.html#exec_nb):\n\n``` python\n!exec_nb --help\n```\n\n usage: exec_nb [-h] [--dest DEST] [--exc_stop] [--inject_code INJECT_CODE]\n [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX]\n src\n\n Execute notebook from `src` and save with outputs to `dest`\n\n positional arguments:\n src Notebook path to read from\n\n optional arguments:\n -h, --help show this help message and exit\n --dest DEST Notebook path to write to (default: )\n --exc_stop Stop on exceptions? (default: False)\n --inject_code INJECT_CODE Code to inject into a cell\n --inject_path INJECT_PATH Path to file containing code to inject into a cell\n --inject_idx INJECT_IDX Cell to replace with `inject_code` (default: 0)\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "A description of your project",
"version": "0.1.8",
"project_urls": {
"Homepage": "https://github.com/fastai/execnb/"
},
"split_keywords": [
"some",
"keywords"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1447c8c31807aed90018742cb0c041acb5e0c2b47ab031e4b2e4457744962c11",
"md5": "ec2495e44c90f093d3eeeda323dff343",
"sha256": "3de90c874d34c9c104407045e4c35e7058f062fc76cf44f87f7a199ba83c3400"
},
"downloads": -1,
"filename": "execnb-0.1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ec2495e44c90f093d3eeeda323dff343",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 13224,
"upload_time": "2024-11-15T21:19:12",
"upload_time_iso_8601": "2024-11-15T21:19:12.881967Z",
"url": "https://files.pythonhosted.org/packages/14/47/c8c31807aed90018742cb0c041acb5e0c2b47ab031e4b2e4457744962c11/execnb-0.1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "99221bcfa6ebc6b6db385c5b32bee1871d95fdbd29c2d47685546414bdcd60bc",
"md5": "a347f2e499cd985e9bd8ca6a9f307fec",
"sha256": "64f4aea889125679800351d834c50e4f0fb9025f612b1a346503ef9d5b218312"
},
"downloads": -1,
"filename": "execnb-0.1.8.tar.gz",
"has_sig": false,
"md5_digest": "a347f2e499cd985e9bd8ca6a9f307fec",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 14561,
"upload_time": "2024-11-15T21:19:14",
"upload_time_iso_8601": "2024-11-15T21:19:14.067479Z",
"url": "https://files.pythonhosted.org/packages/99/22/1bcfa6ebc6b6db385c5b32bee1871d95fdbd29c2d47685546414bdcd60bc/execnb-0.1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-15 21:19:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "fastai",
"github_project": "execnb",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "execnb"
}