NetworkX
  • Overview
    • Who uses NetworkX?
    • Goals
    • The Python programming language
    • Free software
    • History
      • What Next
  • Download
    • Software
    • Documentation
  • Installing
    • Quick install
    • Installing from source
      • Source archive file
      • GitHub
    • Requirements
      • Python
    • Optional packages
      • NumPy
      • SciPy
      • Matplotlib
      • GraphViz
      • PyYAML
      • Other packages
  • Tutorial
    • Creating a graph
    • Nodes
    • Edges
    • What to use as nodes and edges
    • Accessing edges
    • Adding attributes to graphs, nodes, and edges
      • Graph attributes
      • Node attributes
      • Edge Attributes
    • Directed graphs
    • Multigraphs
    • Graph generators and graph operations
    • Analyzing graphs
    • Drawing graphs
  • Reference
    • Introduction
      • NetworkX Basics
        • Graphs
      • Nodes and Edges
        • Graph Creation
        • Graph Reporting
        • Algorithms
        • Drawing
        • Data Structure
    • Graph types
      • Which graph class should I use?
      • Basic graph types
        • Graph – Undirected graphs with self loops
        • DiGraph - Directed graphs with self loops
        • MultiGraph - Undirected graphs with self loops and parallel edges
        • MultiDiGraph - Directed graphs with self loops and parallel edges
    • Algorithms
      • Approximation
        • Connectivity
        • K-components
        • Clique
        • Clustering
        • Dominating Set
        • Independent Set
        • Matching
        • Ramsey
        • Vertex Cover
      • Assortativity
        • Assortativity
        • Average neighbor degree
        • Average degree connectivity
        • Mixing
      • Bipartite
        • Basic functions
        • Matching
        • Matrix
        • Projections
        • Spectral
        • Clustering
        • Redundancy
        • Centrality
        • Generators
      • Blockmodeling
        • blockmodel
      • Boundary
        • edge_boundary
        • node_boundary
      • Centrality
        • Degree
        • Closeness
        • Betweenness
        • Current Flow Closeness
        • Current-Flow Betweenness
        • Eigenvector
        • Communicability
        • Load
        • Dispersion
      • Chordal
        • is_chordal
        • chordal_graph_cliques
        • chordal_graph_treewidth
        • find_induced_nodes
      • Clique
        • Cliques
        • enumerate_all_cliques
        • find_cliques
        • make_max_clique_graph
        • make_clique_bipartite
        • graph_clique_number
        • graph_number_of_cliques
        • node_clique_number
        • number_of_cliques
        • cliques_containing_node
      • Clustering
        • triangles
        • transitivity
        • clustering
        • average_clustering
        • square_clustering
      • Coloring
        • greedy_color
      • Communities
        • K-Clique
      • Components
        • Connectivity
        • Strong connectivity
        • Weak connectivity
        • Attracting components
        • Biconnected components
        • Semiconnectedness
      • Connectivity
        • K-node-components
        • K-node-cutsets
        • Flow-based Connectivity
        • Flow-based Minimum Cuts
        • Stoer-Wagner minimum cut
        • Utils for flow-based connectivity
      • Cores
        • core_number
        • k_core
        • k_shell
        • k_crust
        • k_corona
      • Cycles
        • Cycle finding algorithms
        • cycle_basis
        • simple_cycles
        • find_cycle
      • Directed Acyclic Graphs
        • ancestors
        • descendants
        • topological_sort
        • topological_sort_recursive
        • is_directed_acyclic_graph
        • is_aperiodic
        • transitive_closure
        • antichains
        • dag_longest_path
        • dag_longest_path_length
      • Distance Measures
        • center
        • diameter
        • eccentricity
        • periphery
        • radius
      • Distance-Regular Graphs
        • Distance-regular graphs
        • is_distance_regular
        • intersection_array
        • global_parameters
      • Dominance
        • immediate_dominators
        • dominance_frontiers
      • Dominating Sets
        • dominating_set
        • is_dominating_set
      • Eulerian
        • is_eulerian
        • eulerian_circuit
      • Flows
        • Maximum Flow
        • Edmonds-Karp
        • Shortest Augmenting Path
        • Preflow-Push
        • Utils
        • Network Simplex
        • Capacity Scaling Minimum Cost Flow
      • Graphical degree sequence
        • is_graphical
        • is_digraphical
        • is_multigraphical
        • is_pseudographical
        • is_valid_degree_sequence_havel_hakimi
        • is_valid_degree_sequence_erdos_gallai
      • Hierarchy
        • flow_hierarchy
      • Hybrid
        • kl_connected_subgraph
        • is_kl_connected
      • Isolates
        • is_isolate
        • isolates
      • Isomorphism
        • is_isomorphic
        • could_be_isomorphic
        • fast_could_be_isomorphic
        • faster_could_be_isomorphic
        • Advanced Interface to VF2 Algorithm
      • Link Analysis
        • PageRank
        • Hits
      • Link Prediction
        • resource_allocation_index
        • jaccard_coefficient
        • adamic_adar_index
        • preferential_attachment
        • cn_soundarajan_hopcroft
        • ra_index_soundarajan_hopcroft
        • within_inter_cluster
      • Matching
        • Matching
        • maximal_matching
        • max_weight_matching
      • Minors
        • contracted_edge
        • contracted_nodes
        • identified_nodes
        • quotient_graph
      • Maximal independent set
        • maximal_independent_set
      • Minimum Spanning Tree
        • minimum_spanning_tree
        • minimum_spanning_edges
      • Operators
        • complement
        • reverse
        • compose
        • union
        • disjoint_union
        • intersection
        • difference
        • symmetric_difference
        • compose_all
        • union_all
        • disjoint_union_all
        • intersection_all
        • cartesian_product
        • lexicographic_product
        • strong_product
        • tensor_product
        • power
      • Rich Club
        • rich_club_coefficient
      • Shortest Paths
        • shortest_path
        • all_shortest_paths
        • shortest_path_length
        • average_shortest_path_length
        • has_path
        • Advanced Interface
        • Dense Graphs
        • A* Algorithm
      • Simple Paths
        • all_simple_paths
        • shortest_simple_paths
      • Swap
        • double_edge_swap
        • connected_double_edge_swap
      • Traversal
        • Depth First Search
        • Breadth First Search
        • Depth First Search on Edges
      • Tree
        • Recognition
        • Branchings and Spanning Arborescences
      • Triads
        • triadic_census
      • Vitality
        • closeness_vitality
    • Functions
      • Graph
        • degree
        • degree_histogram
        • density
        • info
        • create_empty_copy
        • is_directed
      • Nodes
        • nodes
        • number_of_nodes
        • nodes_iter
        • all_neighbors
        • non_neighbors
        • common_neighbors
      • Edges
        • edges
        • number_of_edges
        • edges_iter
        • non_edges
      • Attributes
        • set_node_attributes
        • get_node_attributes
        • set_edge_attributes
        • get_edge_attributes
      • Freezing graph structure
        • freeze
        • is_frozen
    • Graph generators
      • Atlas
        • graph_atlas_g
      • Classic
        • balanced_tree
        • barbell_graph
        • complete_graph
        • complete_multipartite_graph
        • circular_ladder_graph
        • cycle_graph
        • dorogovtsev_goltsev_mendes_graph
        • empty_graph
        • grid_2d_graph
        • grid_graph
        • hypercube_graph
        • ladder_graph
        • lollipop_graph
        • null_graph
        • path_graph
        • star_graph
        • trivial_graph
        • wheel_graph
      • Expanders
        • margulis_gabber_galil_graph
        • chordal_cycle_graph
      • Small
        • make_small_graph
        • LCF_graph
        • bull_graph
        • chvatal_graph
        • cubical_graph
        • desargues_graph
        • diamond_graph
        • dodecahedral_graph
        • frucht_graph
        • heawood_graph
        • house_graph
        • house_x_graph
        • icosahedral_graph
        • krackhardt_kite_graph
        • moebius_kantor_graph
        • octahedral_graph
        • pappus_graph
        • petersen_graph
        • sedgewick_maze_graph
        • tetrahedral_graph
        • truncated_cube_graph
        • truncated_tetrahedron_graph
        • tutte_graph
      • Random Graphs
        • fast_gnp_random_graph
        • gnp_random_graph
        • dense_gnm_random_graph
        • gnm_random_graph
        • erdos_renyi_graph
        • binomial_graph
        • newman_watts_strogatz_graph
        • watts_strogatz_graph
        • connected_watts_strogatz_graph
        • random_regular_graph
        • barabasi_albert_graph
        • powerlaw_cluster_graph
        • duplication_divergence_graph
        • random_lobster
        • random_shell_graph
        • random_powerlaw_tree
        • random_powerlaw_tree_sequence
      • Degree Sequence
        • configuration_model
        • directed_configuration_model
        • expected_degree_graph
        • havel_hakimi_graph
        • directed_havel_hakimi_graph
        • degree_sequence_tree
        • random_degree_sequence_graph
      • Random Clustered
        • random_clustered_graph
      • Directed
        • gn_graph
        • gnr_graph
        • gnc_graph
        • scale_free_graph
      • Geometric
        • random_geometric_graph
        • geographical_threshold_graph
        • waxman_graph
        • navigable_small_world_graph
      • Line Graph
        • line_graph
      • Ego Graph
        • ego_graph
      • Stochastic
        • stochastic_graph
      • Intersection
        • uniform_random_intersection_graph
        • k_random_intersection_graph
        • general_random_intersection_graph
      • Social Networks
        • karate_club_graph
        • davis_southern_women_graph
        • florentine_families_graph
      • Community
        • caveman_graph
        • connected_caveman_graph
        • relaxed_caveman_graph
        • random_partition_graph
        • planted_partition_graph
        • gaussian_random_partition_graph
      • Non Isomorphic Trees
        • nonisomorphic_trees
        • number_of_nonisomorphic_trees
    • Linear algebra
      • Graph Matrix
        • adjacency_matrix
        • incidence_matrix
      • Laplacian Matrix
        • laplacian_matrix
        • normalized_laplacian_matrix
        • directed_laplacian_matrix
      • Spectrum
        • laplacian_spectrum
        • adjacency_spectrum
      • Algebraic Connectivity
        • algebraic_connectivity
        • fiedler_vector
        • spectral_ordering
      • Attribute Matrices
        • attr_matrix
        • attr_sparse_matrix
    • Converting to and from other data formats
      • To NetworkX Graph
        • to_networkx_graph
      • Dictionaries
        • to_dict_of_dicts
        • from_dict_of_dicts
      • Lists
        • to_dict_of_lists
        • from_dict_of_lists
        • to_edgelist
        • from_edgelist
      • Numpy
        • to_numpy_matrix
        • to_numpy_recarray
        • from_numpy_matrix
      • Scipy
        • to_scipy_sparse_matrix
        • from_scipy_sparse_matrix
      • Pandas
        • to_pandas_dataframe
        • from_pandas_dataframe
    • Relabeling nodes
      • Relabeling
        • convert_node_labels_to_integers
        • relabel_nodes
    • Reading and writing graphs
      • Adjacency List
        • Adjacency List
        • read_adjlist
        • write_adjlist
        • parse_adjlist
        • generate_adjlist
      • Multiline Adjacency List
        • Multi-line Adjacency List
        • read_multiline_adjlist
        • write_multiline_adjlist
        • parse_multiline_adjlist
        • generate_multiline_adjlist
      • Edge List
        • Edge Lists
        • read_edgelist
        • write_edgelist
        • read_weighted_edgelist
        • write_weighted_edgelist
        • generate_edgelist
        • parse_edgelist
      • GEXF
        • GEXF
        • read_gexf
        • write_gexf
        • relabel_gexf_graph
      • GML
        • Format
        • read_gml
        • write_gml
        • parse_gml
        • generate_gml
        • literal_destringizer
        • literal_stringizer
      • Pickle
        • Pickled Graphs
        • read_gpickle
        • write_gpickle
      • GraphML
        • GraphML
        • read_graphml
        • write_graphml
      • JSON
        • JSON data
        • node_link_data
        • node_link_graph
        • adjacency_data
        • adjacency_graph
        • tree_data
        • tree_graph
      • LEDA
        • Format
        • read_leda
        • parse_leda
      • YAML
        • YAML
        • read_yaml
        • write_yaml
      • SparseGraph6
        • Graph6
        • Sparse6
      • Pajek
        • Pajek
        • read_pajek
        • write_pajek
        • parse_pajek
      • GIS Shapefile
        • Shapefile
        • read_shp
        • write_shp
    • Drawing
      • Matplotlib
        • Matplotlib
        • draw
        • draw_networkx
        • draw_networkx_nodes
        • draw_networkx_edges
        • draw_networkx_labels
        • draw_networkx_edge_labels
        • draw_circular
        • draw_random
        • draw_spectral
        • draw_spring
        • draw_shell
        • draw_graphviz
      • Graphviz AGraph (dot)
        • Graphviz AGraph
        • from_agraph
        • to_agraph
        • write_dot
        • read_dot
        • graphviz_layout
        • pygraphviz_layout
      • Graphviz with pydot
        • Pydot
        • from_pydot
        • to_pydot
        • write_dot
        • read_dot
        • graphviz_layout
        • pydot_layout
      • Graph Layout
        • Layout
        • circular_layout
        • random_layout
        • shell_layout
        • spring_layout
        • spectral_layout
    • Exceptions
      • Exceptions
    • Utilities
      • Helper Functions
        • is_string_like
        • flatten
        • iterable
        • is_list_of_ints
        • make_str
        • generate_unique_node
        • default_opener
      • Data Structures and Algorithms
        • union
      • Random Sequence Generators
        • create_degree_sequence
        • pareto_sequence
        • powerlaw_sequence
        • uniform_sequence
        • cumulative_distribution
        • discrete_sequence
        • zipf_sequence
        • zipf_rv
        • random_weighted_sample
        • weighted_choice
      • Decorators
        • open_file
      • Cuthill-Mckee Ordering
        • cuthill_mckee_ordering
        • reverse_cuthill_mckee_ordering
      • Context Managers
        • reversed
    • License
    • Citing
    • Credits
      • Contributions
        • Original Authors
        • Contributors
      • Support
        • Research Groups
        • Funding
    • Glossary
    • Reference
      • Overview
        • Who uses NetworkX?
        • Goals
        • The Python programming language
        • Free software
        • History
      • Introduction
        • NetworkX Basics
        • Nodes and Edges
      • Graph types
        • Which graph class should I use?
        • Basic graph types
      • Algorithms
        • Approximation
        • Assortativity
        • Bipartite
        • Blockmodeling
        • Boundary
        • Centrality
        • Chordal
        • Clique
        • Clustering
        • Coloring
        • Communities
        • Components
        • Connectivity
        • Cores
        • Cycles
        • Directed Acyclic Graphs
        • Distance Measures
        • Distance-Regular Graphs
        • Dominance
        • Dominating Sets
        • Eulerian
        • Flows
        • Graphical degree sequence
        • Hierarchy
        • Hybrid
        • Isolates
        • Isomorphism
        • Link Analysis
        • Link Prediction
        • Matching
        • Minors
        • Maximal independent set
        • Minimum Spanning Tree
        • Operators
        • Rich Club
        • Shortest Paths
        • Simple Paths
        • Swap
        • Traversal
        • Tree
        • Triads
        • Vitality
      • Functions
        • Graph
        • Nodes
        • Edges
        • Attributes
        • Freezing graph structure
      • Graph generators
        • Atlas
        • Classic
        • Expanders
        • Small
        • Random Graphs
        • Degree Sequence
        • Random Clustered
        • Directed
        • Geometric
        • Line Graph
        • Ego Graph
        • Stochastic
        • Intersection
        • Social Networks
        • Community
        • Non Isomorphic Trees
      • Linear algebra
        • Graph Matrix
        • Laplacian Matrix
        • Spectrum
        • Algebraic Connectivity
        • Attribute Matrices
      • Converting to and from other data formats
        • To NetworkX Graph
        • Dictionaries
        • Lists
        • Numpy
        • Scipy
        • Pandas
      • Reading and writing graphs
        • Adjacency List
        • Multiline Adjacency List
        • Edge List
        • GEXF
        • GML
        • Pickle
        • GraphML
        • JSON
        • LEDA
        • YAML
        • SparseGraph6
        • Pajek
        • GIS Shapefile
      • Drawing
        • Matplotlib
        • Graphviz AGraph (dot)
        • Graphviz with pydot
        • Graph Layout
      • Exceptions
        • Exceptions
      • Utilities
        • Helper Functions
        • Data Structures and Algorithms
        • Random Sequence Generators
        • Decorators
        • Cuthill-Mckee Ordering
        • Context Managers
      • License
      • Citing
      • Credits
        • Contributions
        • Support
      • Glossary
  • Testing
    • Requirements for testing
    • Testing a source distribution
    • Testing an installed package
    • Testing for developers
  • Developer Guide
    • Working with networkx source code
      • Introduction
      • Install git
        • Overview
        • In detail
      • Following the latest source
        • Get the local copy of the code
        • Updating the code
      • Making a patch
        • Making patches
        • Moving from patching to development
      • Git for development
        • Making your own copy (fork) of networkx
        • Set up your fork
        • Configure git
        • Development workflow
        • Maintainer workflow
      • git resources
        • Tutorials and summaries
        • Manual pages online
  • History
    • API changes
      • Version 1.10 notes and API changes
        • API changes
        • New functionalities
        • Removed functionalities
        • Miscellaneous changes
      • Version 1.9 notes and API changes
        • Flow package
        • Connectivity package
        • Other new functionalities
        • Miscellaneous changes
      • Version 1.8 notes and API changes
      • Version 1.7 notes and API changes
        • Other
      • Version 1.6 notes and API changes
        • Graph Classes
        • Weighted graph algorithms
        • Isomorphisms
        • Other
      • Version 1.5 notes and API changes
        • Weighted graph algorithms
        • Random geometric graph
      • Version 1.4 notes and API changes
        • Algorithms changed
      • Version 1.0 notes and API changes
        • Version numbering
        • Changes in base classes
        • Additional functions/generators
        • Converting your existing code to networkx-1.0
      • Version 0.99 API changes
        • Changes in base classes
        • Other possible incompatibilities with existing code
        • Converting your old code to Version 0.99
    • Release Log
      • NetworkX 2.0
      • NetworkX 1.9.1
      • NetworkX 1.9
        • Highlights
        • API changes
      • NetworkX 1.8.1
      • NetworkX 1.8
        • Highlights
        • Bug fixes
        • API changes
      • NetworkX 1.7
        • Highlights
        • API changes
      • NetworkX 1.6
        • Highlights
        • API changes
      • NetworkX 1.5
        • Highlights
        • New features
        • API changes
        • Bug fixes
      • NetworkX 1.4
        • New features
        • API changes
        • Bug fixes
      • NetworkX 1.3
        • New features
        • API changes
        • Bug fixes
      • NetworkX 1.2
        • New features
      • NetworkX 1.1
        • New features
        • API changes
        • Examples
        • Bug fixes
      • NetworkX 1.0.1
      • NetworkX 1.0
        • New features
        • Examples
      • NetworkX 0.99
        • New features
        • Bug fixes
        • Examples
      • NetworkX 0.37
        • New features
        • Bug fixes
        • Examples
      • NetworkX 0.36
        • New features
        • Bug fixes
      • NetworkX 0.35.1
      • NetworkX 0.35
        • New features
        • Bug fixes
      • NetworkX 0.34
        • New features
        • Bug fixes
      • NetworkX 0.33
        • New features
        • Bug fixes
        • Examples
      • NetworkX 0.32
        • New features
        • Bug fixes
        • Examples
      • NetworkX 0.31
        • New features
        • Bug fixes
        • Examples
      • NetworkX 0.30
        • New features
        • Bug fixes
        • Examples
      • NetworkX 0.29
        • New features
        • Bug fixes
      • NetworkX 0.28
        • New features
        • Examples
        • Bug fixes
      • NetworkX 0.27
        • New features
        • Examples
        • Bug fixes
      • NetworkX 0.26
        • New features
        • Examples
        • Bug fixes
      • NetworkX 0.25
        • New features
        • Examples
        • Documentation
        • Bug fixes
      • NetworkX 0.24
        • Bug fixes
      • NetworkX 0.23
        • Important Change
        • New features
        • Examples
        • Documentation
        • Bug fixes
      • NetworkX 0.22
        • New features
        • Examples
        • Documentation
        • Bug fixes
  • Bibliography
  • NetworkX Examples
    • 3D_Drawing
      • Mayavi2 Spring
    • Advanced
      • Eigenvalues
      • Heavy Metal Umlaut
      • Iterated Dynamical Systems
      • Parallel Betweenness
    • Algorithms
      • Blockmodel
      • Davis Club
      • Krackhardt Centrality
      • Rcm
    • Basic
      • Properties
      • Read Write
    • Drawing
      • Atlas
      • Chess Masters
      • Circular Tree
      • Degree Histogram
      • Edge Colormap
      • Ego Graph
      • Four Grids
      • Giant Component
      • House With Colors
      • Knuth Miles
      • Labels And Colors
      • Lanl Routes
      • Node Colormap
      • Random Geometric Graph
      • Sampson
      • Simple Path
      • Unix Email
      • Weighted Graph
    • Graph
      • Atlas
      • Atlas2
      • Degree Sequence
      • Erdos Renyi
      • Expected Degree Sequence
      • Football
      • Karate Club
      • Knuth Miles
      • Napoleon Russian Campaign
      • Roget
      • Unix Email
      • Words
    • Javascript
      • Force
      • Http Server
    • Multigraph
      • Chess Masters
    • Pygraphviz
      • Pygraphviz Attributes
      • Pygraphviz Draw
      • Pygraphviz Simple
      • Write Dotfile
    • Subclass
      • Antigraph
      • Printgraph
 
NetworkX
  • Docs »
  • Reference »
  • Reference »
  • Reading and writing graphs »
  • JSON »
  • node_link_data

node_link_data¶

node_link_data(G, attrs={'source': 'source', 'target': 'target', 'key': 'key', 'id': 'id'})¶

Return data in node-link format that is suitable for JSON serialization and use in Javascript documents.

Parameters:
  • G (NetworkX graph) –
  • attrs (dict) –

    A dictionary that contains four keys ‘id’, ‘source’, ‘target’ and ‘key’. The corresponding values provide the attribute names for storing NetworkX-internal graph data. The values should be unique. Default value: dict(id='id', source='source', target='target', key='key').

    If some user-defined graph data use these attribute names as data keys, they may be silently dropped.

Returns:

data – A dictionary with node-link formatted data.

Return type:

dict

Raises :

NetworkXError – If values in attrs are not unique.

Examples

>>> from networkx.readwrite import json_graph
>>> G = nx.Graph([(1,2)])
>>> data = json_graph.node_link_data(G)

To serialize with json

>>> import json
>>> s = json.dumps(data)

Notes

Graph, node, and link attributes are stored in this format. Note that attribute keys will be converted to strings in order to comply with JSON.

The default value of attrs will be changed in a future release of NetworkX.

See also

node_link_graph(), adjacency_data(), tree_data()

Next Previous

© Copyright 2015, NetworkX Developers. Last updated on Sep 26, 2015.

Built with Sphinx using a theme provided by Read the Docs.