Skip to main content

py2nb: convert python scripts to jupyter notebooks

Project description

py2nb:

convert python scripts to jupyter notebooks

Author:

Will Handley

Version:
1.0.0
Homepage:

https://github.com/williamjameshandley/py2nb

PyPi location

Description

py2nb is a python package for converting python scripts with minimal markdown to jupyter notebooks.

Markdown cells are rendered from comments beginning with #|, splits between code cells are created by comment lines beginning with #-

nb2py converts from jupyter notebooks to python

Installation

Users can install using pip:

pip install py2nb

from source:

git clone https://github.com/williamjameshandley/py2nb
cd py2nb
python setup.py install

or for those on Arch linux it is available on the AUR

Example

If one has a script named example.py containing the code:

#| # Testing ipython notebook
#| This is designed to demonstrate a simple script that converts a script into
#| a jupyter notebook with a simple additional markdown format.
#|
#| Code by default will be put into code cells
#|
#| * To make a markdown cell, prefix the comment line with with '#|' or '# |'
#| * To split a code cell, add a line beginning with '#-' or '# -'

import matplotlib.pyplot as plt
import numpy

%matplotlib inline

#| Here is a markdown cell.
#| Maths is also possible: $A=B$
#|
#| There are code cells below, split by `'#-'`:

# | Here is another markdown cell

x = numpy.random.rand(5)

#-------------------------------

y = numpy.random.rand(4)
z = numpy.random.rand(3)

#| Here are some plots

x = numpy.linspace(-2,2,1000)
y = x**3
fig, ax = plt.subplots()
ax.plot(x,y)

# -------------------------------

# | Here is another plot

x = np.linspace(-np.pi, np.pi, 201)
fig, ax = plt.subplots()
ax.plot(x,np.sin(x))

then running

py2nb example.py

produces the notebook example.ipynb

To do

  • evaluation option for script produced

  • vim syntax highlighting for markdown code blocks

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

py2nb-1.0.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file py2nb-1.0.0.tar.gz.

File metadata

  • Download URL: py2nb-1.0.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.8

File hashes

Hashes for py2nb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d250d734407d635288d38b8fd5ab434b9caa38047258fb4a567bd4feeb3248c9
MD5 773e758c9640d2ed3e06a0a8f715e860
BLAKE2b-256 a972a2e63be57d6c16775105dfd17bd4054775bd64326851d1731e3bbd66907a

See more details on using hashes here.

Supported by

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