Skip to content

Latest commit

 

History

History
122 lines (71 loc) · 2.87 KB

api.rst

File metadata and controls

122 lines (71 loc) · 2.87 KB

Python API for working with notebook files

nbformat

Reading and writing

read

reads

The reading functions require you to pass the as_version parameter. Your code should specify the notebook format that it knows how to work with: for instance, if your code handles version 4 notebooks:

nb = nbformat.read('path/to/notebook.ipynb', as_version=4)

This will automatically upgrade or downgrade notebooks in other versions of the notebook format to the structure your code knows about.

write

writes

NO_CONVERT

This special value can be passed to the reading and writing functions, to indicate that the notebook should be loaded/saved in the format it's supplied.

current_nbformat current_nbformat_minor

These integers represent the current notebook format version that the nbformat module knows about.

NotebookNode objects

The functions in this module work with NotebookNode objects, which are like dictionaries, but allow attribute access (nb.cells). The structure of these objects matches the notebook format described in format_description.

NotebookNode

from_dict

Other functions

convert

validate

ValidationError

Constructing notebooks programmatically

nbformat.v4

These functions return ~.NotebookNode objects with the necessary fields.

new_notebook

new_code_cell

new_markdown_cell

new_raw_cell

new_output

output_from_msg

Notebook signatures

nbformat.sign

This machinery is used by the notebook web application to record which notebooks are trusted, and may show dynamic output as soon as they're loaded. See notebook:notebook_security for more information.

NotebookNotary

sign

unsign

check_signature

mark_cells

check_cells

Signature storage

Signatures are stored using a pluggable SignatureStore subclass. To implement your own, override the methods below and configure NotebookNotary.store_factory.

SignatureStore

store_signature

remove_signature

check_signature

close

By default, NotebookNotary will use an SQLite based store if SQLite bindings are available, and an in-memory store otherwise.

SQLiteSignatureStore

MemorySignatureStore