Skip to main content

Get your code into a jupyter notebook. Anytime. Anywhere.

Check out my SciPy 2018 talk for the motivation and a feature tour of pynt.

MELPA PyPI version Built with Spacemacs

Features

Generate jupyter notebooks on the fly

No more copy and pasting code into jupyter notebooks. Each line of code gets its own cell.

Alt Text

Alt Text

Attach a jupyter notebook to a running process

Run a command which hits the code in the notebook. Restart the notebook kernel to attach to that process.

Alt Text

Alt Text

Syntax transformations

Unroll the first pass of loops for increased interactivity.

Alt Text

Alt Text

Scroll the resulting jupyter notebook with the code buffer

Never forget which cell a code line corresponds to.

Alt Text

Alt Text

Quick Start

Disclaimer: pynt is in beta. Make sure to back-up your code before using it!

Install the codebook module from PyPI with pip.

$ pip install codebook

Then install pynt in emacs through MELPA.

M-x package-install RET pynt

The next time you visit a python file pynt mode will be active.

What is pynt?

pynt is an emacs minor mode for getting source code into jupyter notebooks so you can hack on it there. If you have access to source code and a command to call it with then you can get your code into a jupyter notebook.

However, just pasting your code into one big jupyter notebook cell is not particularly useful. pynt also

  • splits up code into cells so it’s easy to evaluate small bits

  • sets up the state required to run code (by allowing you to attach notebooks to external processes)

  • takes code previously buried in various namespaces (e.g. functions and loops) and exposes them to the global namespace so you can interact with them

Using pynt

It is highly recommended that you familiarize yourself with Emacs IPython Notebook (EIN) first as pynt, at its core, is a tool to make working with EIN easier.

Once you have opened a python file and pynt mode is active, cursor over to the region of code you would like to dump into a notebook and hit C-c C-s. If you need to “re-dump” the code into the notebook then hit C-c C-e.

If you want to attach a jupyter notebook to a running process, then run a command which hits the jupyter notebook code. Restart the jupyter notebook kernel with C-c C-r (ein:notebook-restart-kernel-command). When you see the message ein: [info] Starting channels WS: ... your notebook is attached!

How pynt works

pynt uses a custom kernel manager for attaching to jupyter notebook kernels started via third-party processes. When pynt generates a jupyter notebook from a code region that code region is replaced with a IPython kernel breakpoint so that subsequent commands that hit it will start a jupyter kernel for the notebook to attach to. See here for more information.

pynt also makes heavy use of the `ast <https://docs.python.org/3/library/ast.html>`__ module to parse your code into chunks which are then dumped into notebook cells.

Metadata

Release files for codebook 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codebook 1.2.2
File Size Uploaded Provenance
codebook-1.2.2.tar.gz 15.1 kB Without provenance Details

Release files / codebook-1.2.2.tar.gz

Download URL codebook-1.2.2.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7330bfc27a525ad11e0acfc6ff2335791912c9d2f899b00f2500fb6df6376c9b
BLAKE2b-256 checksum
How to use checksums
58e1cb47797f23769bc26a78f5d990ead1d5e431a47bf3803240900b6d79efe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for codebook 1.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page