17.1.1.3.1.2. cobra.io.json

17.1.1.3.1.2.1. Module Contents

17.1.1.3.1.2.1.1. Functions

to_json(model, sort=False, **kwargs)

Return the model as a JSON document.

from_json(document)

Load a cobra model from a JSON document.

save_json_model(model, filename, sort=False, pretty=False, **kwargs)

Write the cobra model to a file in JSON format.

load_json_model(filename)

Load a cobra model from a file in JSON format.

cobra.io.json.JSON_SPEC = 1[source]
cobra.io.json.to_json(model, sort=False, **kwargs)[source]

Return the model as a JSON document.

kwargs are passed on to json.dumps.

Parameters
  • model (cobra.Model) – The cobra model to represent.

  • sort (bool, optional) – Whether to sort the metabolites, reactions, and genes or maintain the order defined in the model.

Returns

String representation of the cobra model as a JSON document.

Return type

str

See also

save_json_model()

Write directly to a file.

json.dumps()

Base function.

cobra.io.json.from_json(document)[source]

Load a cobra model from a JSON document.

Parameters

document (str) – The JSON document representation of a cobra model.

Returns

The cobra model as represented in the JSON document.

Return type

cobra.Model

See also

load_json_model()

Load directly from a file.

cobra.io.json.save_json_model(model, filename, sort=False, pretty=False, **kwargs)[source]

Write the cobra model to a file in JSON format.

kwargs are passed on to json.dump.

Parameters
  • model (cobra.Model) – The cobra model to represent.

  • filename (str or file-like) – File path or descriptor that the JSON representation should be written to.

  • sort (bool, optional) – Whether to sort the metabolites, reactions, and genes or maintain the order defined in the model.

  • pretty (bool, optional) – Whether to format the JSON more compactly (default) or in a more verbose but easier to read fashion. Can be partially overwritten by the kwargs.

See also

to_json()

Return a string representation.

json.dump()

Base function.

cobra.io.json.load_json_model(filename)[source]

Load a cobra model from a file in JSON format.

Parameters

filename (str or file-like) – File path or descriptor that contains the JSON document describing the cobra model.

Returns

The cobra model as represented in the JSON document.

Return type

cobra.Model

See also

from_json()

Load from a string.

cobra.io.json.json_schema[source]