Skip to main content

nbmanips allows you easily manipulate ipynb files

Project description

nbmanips

PyPI - License PyPI - Python Version PyPI - Wheel PyPI

A collections of utilities to manipulate IPython/Jupyter Notebooks via a python script.

Usage/Examples

Basic usage

A simple example of using nbmanips:

from nbmanips import Notebook

# Read ipynb file
nb = Notebook.read_ipynb("my_notebook.ipynb")

# delete empty cells
nb.delete("empty")

# save ipynb file
nb.to_ipynb("new_notebook.ipynb")

Examples of operations you can perform on a Notebook:

  • replace: Replace matching text in the selected cells
  • tag: Add metadata to the selected cells
  • erase: Erase the content of the selected cells
  • delete: Delete the selected cells
  • keep: Kepp the selected cells

Selectors

To select cells on which to apply the previous operations, you can use:

  • The cell number
nb.show(0)
  • A slice object
selected_cells = slice(1, 6, 2)

nb.show(selected_cells)
  • A predefined selector. Available predefined selectors are the following:

    • code_cells / markdown_cells / raw_cells: Selects cells with the given type
    • contains: Selects Cells containing a certain text.
    • is_empty / empty: Selects empty cells
    • has_output: Checks if the cell has any output
    • has_output_type: Select cells that have a given output_type
    • has_slide_type: Select cells that have a given slide type
    • is_new_slide: Selects cells where a new slide/subslide starts
# Show Markdown Cells
nb.show('markdown_cells')

# Show Cells containing the equal sign
nb.show('contains', '=')
  • A function that takes a Cell object and returns True if the cell should be selected
# Show Cells with length > 10
nb.show(lambda cell: len(cell.source) > 10)
  • A list of Selectors
# Show Empty Markdown Cells
nb.show(['markdown_cells', 'is_empty'])

# Show Markdown or Code Cells
nb.show(['markdown_cells', 'code_cells'], type='or')

Export Formats

You can export the notebooks to these formats:

  • to_ipynb
  • to_html
  • to_slides (using reveal.js)
  • to_md (to markdown)
  • to_py (to python)
  • to_text (textual representation of the notebook)

Slide manipulations

You can manipulate the slides by tagging which cells to keep and which to skip. The following actions are available:

  • set_slide
  • set_subslide
  • set_skip
  • set_fragment
  • set_notes

A neat trick is to use auto_slide method to automatically create slides out of your notebook:

from nbmanips import Notebook

# Read ipynb file
nb = Notebook.read_ipynb("my_notebook.ipynb")

# Automatically create slides
nb.auto_slide()

# Export to Reveal.js slides (HTML)
nb.to_slides("new_slides.slides.html", theme='beige')

Roadmap

  • Add Custom Templates

  • Add CLI

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

nbmanips-0.0.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

nbmanips-0.0.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file nbmanips-0.0.1.tar.gz.

File metadata

  • Download URL: nbmanips-0.0.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.6.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.13

File hashes

Hashes for nbmanips-0.0.1.tar.gz
Algorithm Hash digest
SHA256 88d4a2fcd83031a8e9ae5422ea63c716d48d1474281ea91ec5203a91b545a2aa
MD5 fc0e39c724c06e85df219182d2b3ddb0
BLAKE2b-256 c36898ca6ad2d2899c148d39d33f4d2815b6838cc8311a6815abd8f946c09831

See more details on using hashes here.

File details

Details for the file nbmanips-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: nbmanips-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.6.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.6.13

File hashes

Hashes for nbmanips-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c0bb283d749de5fdced530e423668f35522221159aba93ccac1712835c4c826
MD5 dcc1f1f3765a2eb8dd1399eec90f4030
BLAKE2b-256 0df597e40ac1975a284c3d8eba7612e85ca7937df264538324226936105a8e7e

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