Warning

This documentation is for an old version of IPython. You can find docs for newer versions here.

Module: nbformat.current

The official API for working with notebooks in the current format version.

Authors:

  • Brian Granger
  • Jonathan Frederic

1 Class

class IPython.nbformat.current.NBFormatError

Bases: exceptions.ValueError

10 Functions

IPython.nbformat.current.docstring_nbformat_mod(func)

Decorator for docstrings referring to classes/functions accessed through nbformat.current.

Put {nbformat_mod} in the docstring in place of ‘IPython.nbformat.v3’.

IPython.nbformat.current.parse_py(s, **kwargs)

Parse a string into a (nbformat, string) tuple.

IPython.nbformat.current.reads_json(s, **kwargs)

Read a JSON notebook from a string and return the NotebookNode object.

IPython.nbformat.current.writes_json(nb, **kwargs)
IPython.nbformat.current.reads_py(s, **kwargs)

Read a .py notebook from a string and return the NotebookNode object.

IPython.nbformat.current.writes_py(nb, **kwargs)
IPython.nbformat.current.reads(s, format, **kwargs)

Read a notebook from a string and return the NotebookNode object.

This function properly handles notebooks of any version. The notebook returned will always be in the current version’s format.

Parameters:

s : unicode

The raw unicode string to read the notebook from.

format : (u’json’, u’ipynb’, u’py’)

The format that the string is in.

Returns:

nb : NotebookNode

The notebook that was read.

IPython.nbformat.current.writes(nb, format, **kwargs)

Write a notebook to a string in a given format in the current nbformat version.

This function always writes the notebook in the current nbformat version.

Parameters:

nb : NotebookNode

The notebook to write.

format : (u’json’, u’ipynb’, u’py’)

The format to write the notebook in.

Returns:

s : unicode

The notebook string.

IPython.nbformat.current.read(fp, format, **kwargs)

Read a notebook from a file and return the NotebookNode object.

This function properly handles notebooks of any version. The notebook returned will always be in the current version’s format.

Parameters:

fp : file

Any file-like object with a read method.

format : (u’json’, u’ipynb’, u’py’)

The format that the string is in.

Returns:

nb : NotebookNode

The notebook that was read.

IPython.nbformat.current.write(nb, fp, format, **kwargs)

Write a notebook to a file in a given format in the current nbformat version.

This function always writes the notebook in the current nbformat version.

Parameters:

nb : NotebookNode

The notebook to write.

fp : file

Any file-like object with a write method.

format : (u’json’, u’ipynb’, u’py’)

The format to write the notebook in.

Returns:

s : unicode

The notebook string.