There are several ways to save and load pandapipes networks which all have their advantages and disadvantages. In general however it is recommended to save networks in JSON files, as it is fast, human readable, a standard format and thus interpretable for many other software packages, and has a very dedicated Encoder/Decoder that is inherited from pandapower.

JSON¶

It is possible to save pandapipes networks to JSON files or as strings in JSON format. The saving function is the same in both cases, the only difference is that the filename parameter is set to None if a JSON string shall be retrieved. In order to load a network from a JSON string a different function has to be used than for loading from file.

to_json(net, filename=None)

Saves a pandapipes Network in JSON format. The index columns of all pandas DataFrames will be saved in ascending order. net elements which name begins with “_” (internal elements) will not be saved. Std types will also not be saved.

Parameters
• net (pandapipesNet) – The pandapipes Network to save.

• filename (str, file-object, default None) – The absolute or relative path to the output file or a writable file-like object. If None, a JSON string is returned.

Returns

JSON string of the Network (only if filename is None)

Example
>>> pandapipes.to_json(net, "example.json")

from_json(filename)

Load a pandapipes network from a JSON file or string. The index of the returned network is not necessarily in the same order as the original network. Index columns of all pandas DataFrames are sorted in ascending order.

Parameters

filename (str, file-object) – The absolute or relative path to the input file or file-like object

Returns

net - The pandapipes network that was saved as JSON

Return type

pandapipesNet

Example
>>> net = pandapipes.from_json("example.json")

from_json_string(json_string)

Load a pandapipes network from a JSON string. The index of the returned network is not necessarily in the same order as the original network. Index columns of all pandas DataFrames are sorted in ascending order.

Parameters

json_string (str) – The JSON string representation of the network

Returns

net - The pandapipes network that was contained in the JSON string

Return type

pandapipesNet

Example
>>> net = pandapipes.from_json_string(json_str)


pickle¶

to_pickle(net, filename)

Saves a pandapipes Network with the pickle library.

Parameters
• net (pandapipesNet) – The pandapipes Network to save.

• filename (str, file-object) – The absolute or relative path to the output file or a writable file-like object

Returns

No output.

Example
>>> pandapipes.to_pickle(net, os.path.join("C:", "example_folder", "example1.p"))  # absolute path
>>> pandapipes.to_pickle(net, "example2.p")  # relative path

from_pickle(filename)

Load a pandapipes format Network from pickle file.

Parameters

filename (str, file-object) – The absolute or relative path to the input file or file-like object

Returns

net - The pandapipes Network which was saved as pickle

Return type

pandapipesNet

Example
>>> net1 = pandapipes.from_pickle(os.path.join("C:", "example_folder", "example1.p"))
>>> net2 = pandapipes.from_pickle("example2.p") #relative path