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.1.0.tar.gz (15.5 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.1.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file py_nb_to_src-0.1.0.tar.gz.

File metadata

  • Download URL: py_nb_to_src-0.1.0.tar.gz
  • Upload date:
  • Size: 15.5 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.1.0.tar.gz
Algorithm Hash digest
SHA256 5d528056a3f576df4b45d7017141fc8ff46d4440e41447a7ec614e75ff0de195
MD5 529dad22856112d40c2c818410ed5f3e
BLAKE2b-256 7fa9e80224a2100fbe5977da0f69ab724dab8e8367fa27799653432d2e397033

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_nb_to_src-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_nb_to_src-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.9 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e1c4fab72b9ebb6b5af0c683774cd0c2ad382ef82a5cc4d8f64cfa7aa438568
MD5 b45619e627c453639e1284ec6846119c
BLAKE2b-256 f16a1d06ddc48ab4bd919c4f7a119279abd6159224b1d1f4cea76bea4a9e09fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_nb_to_src-0.1.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