Skip to main content

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 knitr R 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 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 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 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}")

Metadata

Release files for py-nb-to-src 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-nb-to-src 0.3.0
File Size Uploaded
py_nb_to_src-0.3.0.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-nb-to-src 0.3.0
File Interpreter ABI Platform
py_nb_to_src-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.1 kB

Release files / py_nb_to_src-0.3.0.tar.gz

Download URL py_nb_to_src-0.3.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ed68520f39a2f9235e6dbc3a390b4c4d7a81341258b2ddba8e0d6563c08e24aa
BLAKE2b-256 checksum
How to use checksums
e59c3d2b5f30426cbf174fcfb81fcece8ac4ce048dcc79158c5c7d05f2f3f811
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2026.

Transparency log

Release files / py_nb_to_src-0.3.0-py3-none-any.whl

Download URL py_nb_to_src-0.3.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1aedf3e8d14d70d53bdd2b3b217c92161d8167d0aa07c6d759cbe4d4800138d
BLAKE2b-256 checksum
How to use checksums
bd31eec1d33127821ef4cc2236066612ca64fb37b1cb5e096138a807da6c0417
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page