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.
pip install jupyter_spacesjupyter_spaces supports Python versions 3.6, 3.7, 3.8, 3.9, 3.10
and 3.11.
%load_ext jupyter_spaces%reload_ext jupyter_spacesReloading the extension will remove all spaces.
%%space <space-name>
alpha = 0.50
alphaWhen 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).
If <space-name> is blank, the cell is executed in a single-use anonymous
namespace, which cannot be accessed later.
%remove_space <space-name>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:
namethe name of the spacenamespacea dictionary with the namespace of the space
Modifying the spaces via get_spaces will actually modify the underlying
spaces.
Many thanks to Yeray Diaz Diaz and Karol Duleba!