Lightweight persistence for python variables.

%store allows you to save a variable and access it after exiting a session. To save a variable, you simply pass it as the sole argument:

In [1]: my_name = 'Eric'

In [2]: %store my_name
Stored 'my_name' (str)

You can then exit the session, enter a new one, and recall it with the -r parameter:

In [3]: exit
ipython --profile=zagnut
In [1]: my_name
Out[1]: NameError: name 'my_name' is not defined

In [2]: %store -r

In [3]: my_name
Out[3]: 'Eric'

You can edit your IPython configuration to always autoload any stored variables.

Additional options

Show a list of all variables and their current values:


Store the current value of the variables eggs and motorcycles:

%store eggs motorcycles

Remove the variable eggs and its value from storage:

%store -d eggs

Remove all variables from storage:

%store -z

It should be noted that if you change the value of a variable, you need to %store it again if you want to persist the new value.