Skip to main content

Create a package from a jupyter notebook

Project description

README

A tiny little package to create packages from jupyter notebooks

If you find yourself copy pasting functions between jupyter notebooks, this might help.

Please note: this allows you to import functions and objects from your notebooks.

Typical Use Cases

This is very helpful when producing the same graph, running the same ETL, or executing the same ML pipeline on different datasets or different versions of the same dataset.

Make Packages from Jupyter Notebooks

In Python

You can run this in <your_notebook.ipynb> or anywhere else in the same directory

from jupyckage.jupyckage import notebook_to_package

notebook_to_package("notebook_name.ipynb")

will create the needed files and directories [in the current directory] to produce a local package

Importing the Package

You can access by

import notebooks.src.<cleaned_notebook_name>.<cleaned_notebook_name>

where cleaned_notebook_name is all lower case and has spaces replaced with underscores. Please note if your notebook name has illegal characters for a python package, there will be an error.

I recommend importing your notebook as an abbreviation-- but as usual please do not import *, for the same reasons as usual.

Make sure to rerun the code if you want the package updated.

From the Command Line

You can enter

jupyckage --nb <notebook_name.ipynb>

in your terminal and the most recent saved version of your notebook will be turned into a package. You can import the package as described above in 'In Python'

Under the Hood: Package Directory Structure

With no consensus on directory structure for packages, I defaulted to a version of python.org's suggestion.

notebooks/
├── src/
│   └── <notebook_name>/
│       ├── __init__.py
│       └── <notebook_name>.py  # what you'll be importing
└── bin/
    └── <notebook_name>.py #executable

I realize the import statement is hefty, but I didn't want to handle collissions in a VO.

Skip Stuff

Aything you don't want included in the package you can put below a MARKDOWN cell including the text between the quotes

"# DO NOT ADD BELOW TO SCRIPT"

FAQs

Help! My code isn't updating!

Make sure that you've run your notebook and saved it. This package relies on jupyter notebook's nbconvert under the hood, which looks to the most recent checkpoint of your notebook.

Help! Why can't jupyckage do more?!?!

If you're interested added functionality, please let me know and I'll look at adding it or happily work with you so you can contribute :)

Help! Why is the import statement so verbose?!?!

I realize the import statement is hefty, but I didn't want to handle collissions in a VO. If you find this package useful and would really love an update or want to contribute, please contact me :)

Contact

Hi, I'm Kerstin Frailey. I whipped up this package quickly to make my life a bit easier. Hope it helps some other people out, too.

Here's the repo info:

Here's my contact info:

  • twitter @KEFrailey
  • blog datascienceatwork.blog
  • email frailey.work@gmail.com
  • linkedin linkedin.com/in/kefrailey

Hope you have a nice day!

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

jupyckage-0.1.5.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

jupyckage-0.1.5-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file jupyckage-0.1.5.tar.gz.

File metadata

  • Download URL: jupyckage-0.1.5.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for jupyckage-0.1.5.tar.gz
Algorithm Hash digest
SHA256 670c89f3c93eceb575d45c6e01850dde934139b1420a693f7bfc5c2c0f0d6a49
MD5 455ac22e08537c511c89bd1054dea05b
BLAKE2b-256 5fde13b807f00458d07ff624ecaecfbcab0063a629a8b25384628f6c8d31de22

See more details on using hashes here.

File details

Details for the file jupyckage-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: jupyckage-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for jupyckage-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9d119eb88aa92609ac6155e49b7f963c6edb3c3fa6ffc262cdd931c694a20da7
MD5 77168afef0d37b8d75a62628b72c4a22
BLAKE2b-256 e4652868f2f30bde6befd91631763ce248a66a5094aa0eb5f20afd4291d8830f

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