Skip to main content

Create parallel namespaces in Jupyter Notebooks

Project description

Jupyter Spaces

Build Status codecov Supported Python Versions

Jupyter Spaces is an IPython extension for creating parallel namespaces available within the user namespace. It is designed to be used via IPython magics in Jupyter notebooks.

Installation

pip install jupyter_spaces

jupyter_spaces supports Python versions 3.4, 3.5, 3.6 and 3.7.

Usage

Load jupyter_spaces extension

%load_ext jupyter_spaces

Reload jupyter_spaces extension

%reload_ext jupyter_spaces

Reloading the extension will remove all spaces.

Run a cell within a space

%%space <space-name>
alpha = 0.50
print(alpha)

When you execute a cell within a space, all references are firstly searched in the space namespace and secondly in the user namespace. All assignments are made in the space namespace.

Trying to delete a user namespace reference will raise an error. Trying to affect a user namespace reference using the keyword global will produce an execution equivalent to not using such keyword.

Mutable objects in the user namespace can be altered (e.g. appending an item to a list).

Console output

Conversely to the standard usage of the Python console, you need to print objects explicitly (e.g. by using print).

  • No output to console
    %%space <space-name>
    100
    
  • Output to console
    %%space <space-name>
    print(100)
    

If you want IPython to use more advanced representations, you can do so via IPython's display library (e.g. display a Pandas dataframe as a HTML table).

%%space <space-name>
from IPython.display import display
from pandas import DataFrame
dataframe = DataFrame(data=[[1, 2]])
display(dataframe)

Remove a space

%remove_space <space-name>

Access all spaces at once

You can access all the spaces' namespaces at once without using any magic. This might be useful to jointly post-process or compare the spaces' contents.

from jupyter_spaces import get_spaces

spaces = get_spaces()
space = spaces[<space-name>]
reference = space.namespace[<reference-name>]

Space objects have two properties:

  • name the name of the space
  • namespace a dictionary with the namespace of the space

Modifying the spaces via get_spaces will actually modify the underlying spaces.

Acknowledgements

Many thanks to Yeray Diaz Diaz and Karol Duleba!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
jupyter_spaces-0.1.2-py3-none-any.whl (5.0 kB) Copy SHA256 hash SHA256 Wheel py3 Jul 18, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page