cytoscape_data

cytoscape_data(G, attrs=None, name='name', ident='id')[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

namestring

A string which is mapped to the ‘name’ node element in cyjs format. Must not have the same value as ident.

identstring

A string which is mapped to the ‘id’ node element in cyjs format. Must not have the same value as name.

Returns
data: dict

A dictionary with cyjs formatted data.

Raises
NetworkXError

If the values for name and ident 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}}]}}