A tool to run Jupyter notebooks as Python scripts
Project description
run-ipynb
Run Jupyter notebooks as plain Python scripts from the command line.
This tool converts a .ipynb to .py, removes IPython-only lines, ensures a non-interactive Matplotlib backend, optionally adjusts sys.path when os.chdir(...) is used, executes the script, and cleans up the generated file by default.
Usage
You can directly use the tool with uv:
uvx run-ipynb path/to/notebook.ipynb [--keep] [--yes]
Optionally specify a Python interpreter:
uvx run-ipynb path/to/notebook.ipynb --python /path/to/python
You can also rely on your current shell's interpreter by setting RUN_IPYNB_PYTHON:
export RUN_IPYNB_PYTHON=$(which python)
uvx run-ipynb path/to/notebook.ipynb
Otherwise run:
pip install run-ipynb
and then:
run-ipynb path/to/notebook.ipynb [--keep] [--yes]
- notebook_path: Path to the
.ipynbnotebook to run - -k, --keep: Keep the generated
.pyfile after execution - -y, --yes: Automatically overwrite an existing
.pyfile without prompting - -p, --python: Python interpreter to execute the generated script (defaults to the current interpreter)
If --python is not provided, run-ipynb checks in order:
RUN_IPYNB_PYTHONRUN_IPYNB_ENV_PYTHON- active virtual environments (
VIRTUAL_ENV,CONDA_PREFIX,MAMBA_PREFIX, Pipenv, Poetry, etc.) which python- the interpreter running the CLI
Examples
# Basic: convert, run, and remove the temporary .py file
uvx run-ipynb notebooks/analysis.ipynb
# Keep the .py file for inspection and overwrite if it already exists
uvx run-ipynb notebooks/analysis.ipynb --keep --yes
What it does
- Converts the notebook with
jupyter nbconvert --to script - Removes
get_ipython().run_line_magiclines - Sets Matplotlib backend to
Aggfor headless environments - If
os.chdir(...)is detected, appendsos.getcwd()tosys.pathright after the change - Executes the resulting script with your current Python interpreter
- Deletes the generated
.pyfile unless--keepis passed
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file run_ipynb-0.1.1.tar.gz.
File metadata
- Download URL: run_ipynb-0.1.1.tar.gz
- Upload date:
- Size: 182.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe852b873e837af2a618ea2274648ddac387c9c4c43fa213e715e8d4f7fe3f28
|
|
| MD5 |
65d7eabdc5247ee28e0c7b46904edc59
|
|
| BLAKE2b-256 |
af0a89406526b98b19c6919baed28650737ac10602dafef0888018d053a521a9
|
Provenance
The following attestation bundles were made for run_ipynb-0.1.1.tar.gz:
Publisher:
release.yaml on dschaub95/run-ipynb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
run_ipynb-0.1.1.tar.gz -
Subject digest:
fe852b873e837af2a618ea2274648ddac387c9c4c43fa213e715e8d4f7fe3f28 - Sigstore transparency entry: 597835986
- Sigstore integration time:
-
Permalink:
dschaub95/run-ipynb@dbe33daf723941154e1882671d1e63dbc32c9f20 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dschaub95
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@dbe33daf723941154e1882671d1e63dbc32c9f20 -
Trigger Event:
release
-
Statement type:
File details
Details for the file run_ipynb-0.1.1-py3-none-any.whl.
File metadata
- Download URL: run_ipynb-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
514ab22df9fd1064a90208654f72bee416c4a8a43d8febb1f08a3e9190cff6aa
|
|
| MD5 |
182f138dba08bb77dfc45c21b9b30cb6
|
|
| BLAKE2b-256 |
7df834e5a92ef73b31b80052b47f5faca87ab4c9946b532cd78426c3552646bd
|
Provenance
The following attestation bundles were made for run_ipynb-0.1.1-py3-none-any.whl:
Publisher:
release.yaml on dschaub95/run-ipynb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
run_ipynb-0.1.1-py3-none-any.whl -
Subject digest:
514ab22df9fd1064a90208654f72bee416c4a8a43d8febb1f08a3e9190cff6aa - Sigstore transparency entry: 597835989
- Sigstore integration time:
-
Permalink:
dschaub95/run-ipynb@dbe33daf723941154e1882671d1e63dbc32c9f20 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dschaub95
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@dbe33daf723941154e1882671d1e63dbc32c9f20 -
Trigger Event:
release
-
Statement type: