Skip to main content

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 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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_nb_to_src-0.2.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_nb_to_src-0.2.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

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

Hashes for py_nb_to_src-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bbd54871cd113efc1e91939ba38d55ad8c016a17a32f18b93092158005ae9b3b
MD5 8943b23b8d9ceef1c2125081a66803be
BLAKE2b-256 e34674d7f8cd119803c117939882af204f1eed4a689f94cdff0749558004c12d

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for py_nb_to_src-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6a32a1a811d0fe7e60a20dd1aae4343047eec42c1289461854cd91e5a1d2b16
MD5 e7cea9f21ae31e04604cd3e40305e95a
BLAKE2b-256 2bd651f3a4f6db07e0698089b0e3f26c378bd34addc5dd34aff37ab077d2fa71

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page