How can we go about using Jupyter notebooks to create Python packages?
One of the ways of saving a Jupyter notebook is as a python file, which could be handy…
One of the ways of using a Jupyer notebook is to run it inside another notebook by calling it using the
%run cell magic – which provides a crude way of importing the contents of one notebook into another.
Another way of using a Jupyter notebook is to treat it as as Python module using a recipe described in Importing Jupyter Notebooks as Modules that hooks into the python import machinery. (It even looks to work with importing notebooks containing code cells that include IPython commands?)
But could we mark up one or more linked notebooks in some way that would build a Python package and zip it up for distribution via
I’ve no idea how it would work, but here’s something related-ish (via @simonw) that creates a command line interface from a Python file: click:
Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It’s the “Command Line Interface Creation Kit”. It’s highly configurable but comes with sensible defaults out of the box.
It aims to make the process of writing command line tools quick and fun while also preventing any frustration caused by the inability to implement an intended CLI API.
I guess it could work on Python exported from a Jupyter notebook too?
TO DO: see if I can write a Jupyter notebook that can be used to generate a CLI, (perhaps creating a Jupyter notebook extension to create a CLI from a notebook?)
See also: oschuett/appmode Jupyter extension for creating and launching a simple web app from a Jupyter notebook.
Hmm… also via @simonw, could Zeit Now be used to launch
appmode apps, as in Datasette: instantly create and publish an API for your SQLite databases?