Skip to main content

Python package to read and write NetworkX graphs as GDF (Graph Data Format).

Project description

networkx-gdf

Python package to read and write NetworkX graphs as GDF (Graph Data Format).

GDF is a compact file format originally implemented by GUESS. Although the software itself is not anymore maintained, the format is still supported by active open-source projects such as Gephi (see details here).

Requirements

  • Python>=3.7
  • networkx>=2.1
  • pandas>=1.1.0

Install

Package is available to install on PyPI:

pip install networkx-gdf

Usage

Just two functions are implemented, for reading from and writing data to file.

from networkx_gdf import read_gdf, write_gdf

# Builds NetworkX graph object from file.
G = read_gdf("input_file.gdf")

# Writes NetworkX graph object to file.
write_gdf(G, "output_file.gdf")

Detailed usage

A few additional arguments are available both for reading and writing files:

Building NetworkX graph object from file

G = read_gdf(
    "input_file.gdf",
    # Required; file path to read data from.

    directed=None,
    # Optional; consider edges as directed or undirected.
    # True: returns a <nx.DiGraph> or <nx.MultiDiGraph> object.
    # False: returns a <nx.Graph> or <nx.MultiGraph> object.
    # None (default): decides based on "directed" edge attribute in file.

    multigraph=None,
    # Optional; consider multiple or single edges among nodes.
    # True: always returns a <nx.MultiGraph> or <nx.MultiDiGraph> object.
    # False: sums edge weights and returns a <nx.Graph> or <nx.DiGraph> object.
    # None (default): decides based on number of edges among the same pair of nodes.

    node_attr=None,
    # Optional; node attributes to import data from.
    # Accepts either a list containing attribute names or a boolean (True, False).
    # Defaults to True, which considers all node attributes.

    edge_attr=None,
    # Optional; edge attributes to import data from.
    # Accepts either a list containing attribute names or a boolean (True, False).
    # Defaults to True, which considers all edge attributes.
)

Writing NetworkX graph object to file

write_gdf(
    G,
    # Required; graph object from NetworkX.

    "output_file.gdf",
    # Required; file path to write data to.

    node_attr=None,
    # Optional; node attributes to export data from.
    # Accepts either a list containing attribute names or a boolean (True, False).
    # Defaults to True, which considers all node attributes.

    edge_attr=None,
    # Optional; edge attributes to export data from.
    # Accepts either a list containing attribute names or a boolean (True, False).
    # Defaults to True, which considers all edge attributes.
)

Note that any object types beyond integers/longs, floats/doubles, and booleans will be considered as strings.

Importing as a class

Alternatively, the module can also be imported as a class and inherited:

from networkx_gdf import GDF

class MyClass(GDF):
    ...

G = MyClass.read_gdf("input_file.gdf")
MyClass.write_gdf(G, "output_file.gdf")

Both functions are implemented as static methods, so initializing the class as an object is not required.


References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

networkx-gdf-1.3.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

networkx_gdf-1.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file networkx-gdf-1.3.tar.gz.

File metadata

  • Download URL: networkx-gdf-1.3.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for networkx-gdf-1.3.tar.gz
Algorithm Hash digest
SHA256 e748cc7f3fab29d3af18cb7221d0a181a31d650a8397d0253f62f51a9c7b1271
MD5 baa8a346f67775f63f07ca9e6227db51
BLAKE2b-256 4e1684a8c172d16f836b8c3d0c8fd2e469d27e9249869a15da794b56735bb7a0

See more details on using hashes here.

File details

Details for the file networkx_gdf-1.3-py3-none-any.whl.

File metadata

  • Download URL: networkx_gdf-1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for networkx_gdf-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1d792d4f016615850303156de5b5561682c991fae629b0784ed3ed8983d2c489
MD5 1c7c8d10052ef3bef96eda3119aaffb9
BLAKE2b-256 265a484d035cafa7fdd8938e9792e4d5e30fb09ebea864a5756ac3c06ce30356

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page