Skip to main content

Utility to turn IPython scripts into Jupyter Notebook format. Forked from py2nb project.

Project description

Features after forking:

  • New token recognized for code cells, defined by #%%, used in Spyder and PyCharm scientific mode.

Original source repo readme follows...

PY2NB: Python To Notebook Converter

This is a small utility for turning python scripts into jupyter notebooks and convert module-level multiline (triple quote) string literals into markdown cells.


I wanted a tool to create user examples that can be executed as normal python scripts so that they can be copy-and-pasted easily and can be rendered as notebook for better readability (e.g nice styling, results embedded).


  • Notebooks are nice to look at but slow to write
  • Notebooks does not play well with version control


python install


To convert a python script into a notebook:

python -m py2nb output.ipynb

Additional commandline not from this package

Execute a notebook:

ipython nbconvert --to=notebook --execute input.ipynb

Convert a notebook to a HTML:

ipython nbconvert --to=html input.ipynb


See "samples" directory.


Uses python tokenize (builtin tokenizer library) for tokenization. String literals with triple quote at column zero are converted into a comment token with special <markdowncell> and <codecell> to feed into the python importer in IPython version 3. The processed tokens are untokenized using the tokenize module so that untouched line looks exactly the same as the input.

Project details

Download files

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

Files for py2jnb, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size py2jnb-0.0.5.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View
Filename, size py2jnb-0.0.5-py2.py3-none-any.whl (9.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page