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.

Why?

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

Also,

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

Install

python setup.py install

Usage

To convert a python script into a notebook:

python -m py2nb input.py 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

Samples

See "samples" directory.

How?

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.

Source Distribution

py2jnb-0.0.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

py2jnb-0.0.5-py2.py3-none-any.whl (9.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file py2jnb-0.0.5.tar.gz.

File metadata

  • Download URL: py2jnb-0.0.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for py2jnb-0.0.5.tar.gz
Algorithm Hash digest
SHA256 2abcaa37cd165dd6de8ac39480462e980cdde15f2ceb011646509f6c1dea5d9b
MD5 36b73a482c3511e78448d0f5ebaf7b8b
BLAKE2b-256 40a646b24ab7d20dd52b37d6123964f4fd32b223f24479456b86c94fedfe8d05

See more details on using hashes here.

File details

Details for the file py2jnb-0.0.5-py2.py3-none-any.whl.

File metadata

  • Download URL: py2jnb-0.0.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for py2jnb-0.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f00da358ce70ab783f86a63a0de2a689df4d05166f6c075fe028f347c884f740
MD5 c21f33ca3e97b1849946fd1686174ce1
BLAKE2b-256 63dbfb155b0ee2ed4bf127142add59a8833baa9c72df94915f9e2fe7cfb6b04f

See more details on using hashes here.

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