Convert Jupyter Notebooks (of all languages) and Rmd to their non-notebook counterparts.
Project description
py-nb-to-src
Convert Jupyter Notebooks (of all languages) and Rmd to their non-notebook counterparts.
Installation
pip install py-nb-to-src
Additional Requirements
For R Markdown (.Rmd) conversion:
- R must be installed and available on your PATH
- The
knitrR package must be installed
The easiest way to install all dependencies is via micromamba/conda:
# Install R and knitr in one command
micromamba install -c conda-forge r-base r-knitr
After installing R, install knitr:
R -e "install.packages('knitr', repos='https://cloud.r-project.org')"
Usage
Converting Jupyter Notebooks
Convert any Jupyter notebook (.ipynb) to its source script. The output format depends on the kernel specified in the notebook (Python, R, Julia, etc.).
from py_nb_to_src import convert_ipynb
# Convert a Python notebook
output_path = convert_ipynb("analysis.ipynb")
# Returns: Path to analysis.py
# Convert an R notebook
output_path = convert_ipynb("analysis_r.ipynb")
# Returns: Path to analysis_r.r
Converting R Markdown Files
Convert R Markdown (.Rmd) files to R scripts (.r) using knitr.
from py_nb_to_src import convert_rmd
# Convert an Rmd file
output_path = convert_rmd("report.Rmd")
# Returns: Path to report.r
Converting a Directory
Convert all notebook files in a directory at once. Returns a DirectoryConversionResult containing successfully converted files and any failures with their tracebacks. A progress bar is displayed by default.
from py_nb_to_src import convert_directory, ConverterType
# Convert all supported files (both .ipynb and .Rmd)
result = convert_directory("notebooks/")
# Convert only Jupyter notebooks
result = convert_directory("notebooks/", ConverterType.IPYNB)
# Convert only R Markdown files
result = convert_directory("notebooks/", ConverterType.RMD)
# Disable progress bar
result = convert_directory("notebooks/", show_progress=False)
# Progress bar that disappears after completion
result = convert_directory("notebooks/", progress_leave=False)
# Access results
for original, converted in result.converted.items():
print(f"{original} -> {converted}")
# Check for failures
for original, traceback in result.failed.items():
print(f"Failed to convert {original}:\n{traceback}")
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 py_nb_to_src-0.2.0.tar.gz.
File metadata
- Download URL: py_nb_to_src-0.2.0.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbd54871cd113efc1e91939ba38d55ad8c016a17a32f18b93092158005ae9b3b
|
|
| MD5 |
8943b23b8d9ceef1c2125081a66803be
|
|
| BLAKE2b-256 |
e34674d7f8cd119803c117939882af204f1eed4a689f94cdff0749558004c12d
|
Provenance
The following attestation bundles were made for py_nb_to_src-0.2.0.tar.gz:
Publisher:
ci.yml on evamaxfield/py-nb-to-src
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_nb_to_src-0.2.0.tar.gz -
Subject digest:
bbd54871cd113efc1e91939ba38d55ad8c016a17a32f18b93092158005ae9b3b - Sigstore transparency entry: 836047070
- Sigstore integration time:
-
Permalink:
evamaxfield/py-nb-to-src@ea6c452a635e552cc7f23e172c4292302171526c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/evamaxfield
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ea6c452a635e552cc7f23e172c4292302171526c -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_nb_to_src-0.2.0-py3-none-any.whl.
File metadata
- Download URL: py_nb_to_src-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.3 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 |
f6a32a1a811d0fe7e60a20dd1aae4343047eec42c1289461854cd91e5a1d2b16
|
|
| MD5 |
e7cea9f21ae31e04604cd3e40305e95a
|
|
| BLAKE2b-256 |
2bd651f3a4f6db07e0698089b0e3f26c378bd34addc5dd34aff37ab077d2fa71
|
Provenance
The following attestation bundles were made for py_nb_to_src-0.2.0-py3-none-any.whl:
Publisher:
ci.yml on evamaxfield/py-nb-to-src
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_nb_to_src-0.2.0-py3-none-any.whl -
Subject digest:
f6a32a1a811d0fe7e60a20dd1aae4343047eec42c1289461854cd91e5a1d2b16 - Sigstore transparency entry: 836047074
- Sigstore integration time:
-
Permalink:
evamaxfield/py-nb-to-src@ea6c452a635e552cc7f23e172c4292302171526c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/evamaxfield
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ea6c452a635e552cc7f23e172c4292302171526c -
Trigger Event:
push
-
Statement type: