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

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.3.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.3.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_nb_to_src-0.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 ed68520f39a2f9235e6dbc3a390b4c4d7a81341258b2ddba8e0d6563c08e24aa
MD5 65757c0e46ec51eadc6511ffa76aeb1e
BLAKE2b-256 e59c3d2b5f30426cbf174fcfb81fcece8ac4ce048dcc79158c5c7d05f2f3f811

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: py_nb_to_src-0.3.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1aedf3e8d14d70d53bdd2b3b217c92161d8167d0aa07c6d759cbe4d4800138d
MD5 4456430ee145049359b8242d7a6f397d
BLAKE2b-256 bd31eec1d33127821ef4cc2236066612ca64fb37b1cb5e096138a807da6c0417

See more details on using hashes here.

Provenance

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