Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

networkx.readwrite.json_graph.cytoscape_data

cytoscape_data(G, attrs=None)[source]

Returns data in Cytoscape JSON format (cyjs).

Parameters
GNetworkX Graph

The graph to convert to cytoscape format

attrsdict or None (default=None)

A dictionary containing the keys ‘name’ and ‘ident’ which are mapped to the ‘name’ and ‘id’ node elements in cyjs format. All other keys are ignored. Default is None which results in the default mapping dict(name="name", ident="id").

Deprecated since version 2.6: The attrs keyword argument will be replaced with name and ident in networkx 3.0

Returns
data: dict

A dictionary with cyjs formatted data.

Raises
NetworkXError

If the name and ident attributes are identical.

See also

cytoscape_graph

convert a dictionary in cyjs format to a graph

References

1

Cytoscape user’s manual: http://manual.cytoscape.org/en/stable/index.html

Examples

>>> G = nx.path_graph(2)
>>> nx.cytoscape_data(G)  
{'data': [],
 'directed': False,
 'multigraph': False,
 'elements': {'nodes': [{'data': {'id': '0', 'value': 0, 'name': '0'}},
   {'data': {'id': '1', 'value': 1, 'name': '1'}}],
  'edges': [{'data': {'source': 0, 'target': 1}}]}}