GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - AnswerDotAI/execnb: Execute a jupyter notebook, fast, without needing jupyter

BranchesTags
Open more actions menu

Latest commit

 

History

315 Commits
315 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
execnb
execnb
 
 
nbs
nbs
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.nojeklyll
.nojeklyll
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
install_quarto.sh
install_quarto.sh
 
 
pyproject.toml
pyproject.toml
 
 
styles.css
styles.css
 
 

Repository files navigation

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 sync – each shell runs cells on its own private event loop in a background thread, so it works the same from a script, a notebook, or an async server, and cells may use top-level await:

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': 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 (str)] [--exc-stop] [--inject-code (str)]
               [--inject-path (str)] [--inject-idx (int)] [--verbose]
               [--cell-timeout (int)]
               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 (str)          Notebook path to write to (default: '')
  --exc-stop            Stop on exceptions? (default: False)
  --inject-code (str)   Code to inject into a cell
  --inject-path (str)   Path to file containing code to inject into a cell
  --inject-idx (int)    Cell to replace with `inject_code` (default: 0)
  --verbose             Show stdout/stderr during execution (default: False)
  --cell-timeout (int)  Seconds before each cell times out (None: no limit)

execnb 0.3.4

About

Execute a jupyter notebook, fast, without needing jupyter

answerdotai.github.io/execnb/

Topics

answeraianswerdotaifastaijupyternbdevnotebook

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

138 stars

Watchers

1 watching

Forks

12 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.