# 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](http://graphexploration.cond.org). Although the software itself is not anymore maintained, the format is still supported by active open-source projects such as [Gephi](https://gephi.org/) (see details [here](https://gephi.org/users/supported-graph-formats/gdf-format/)).
## Requirements
* **Python>=3.7**
* networkx>=2.1
* pandas>=1.1.0
## Install
Package is available to install on [PyPI](https://pypi.org/project/networkx-gdf/):
```bash
pip install networkx-gdf
```
## Usage
Just two functions are implemented, for reading from and writing data to file.
```python
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
```python
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
```python
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:
```python
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
* [NetworkX](https://networkx.github.io)
* [Pandas](https://pandas.pydata.org/)
Raw data
{
"_id": null,
"home_page": "https://github.com/nelsonaloysio/networkx-gdf",
"name": "networkx-gdf",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "Network,Graph,GDF",
"author": "Nelson Aloysio Reis de Almeida Passos",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/3e/4e/8c55ff1a87859a37d262c2156731f71b99e8ef9ff03ff5d81013336f3e98/networkx-gdf-1.3.2.tar.gz",
"platform": null,
"description": "# networkx-gdf\n\nPython package to read and write NetworkX graphs as GDF (Graph Data Format).\n\nGDF is a compact file format originally implemented by [GUESS](http://graphexploration.cond.org). Although the software itself is not anymore maintained, the format is still supported by active open-source projects such as [Gephi](https://gephi.org/) (see details [here](https://gephi.org/users/supported-graph-formats/gdf-format/)).\n\n## Requirements\n\n* **Python>=3.7**\n* networkx>=2.1\n* pandas>=1.1.0\n\n## Install\n\nPackage is available to install on [PyPI](https://pypi.org/project/networkx-gdf/):\n\n```bash\npip install networkx-gdf\n```\n\n## Usage\n\nJust two functions are implemented, for reading from and writing data to file.\n\n```python\nfrom networkx_gdf import read_gdf, write_gdf\n\n# Builds NetworkX graph object from file.\nG = read_gdf(\"input_file.gdf\")\n\n# Writes NetworkX graph object to file.\nwrite_gdf(G, \"output_file.gdf\")\n```\n\n### Detailed usage\n\nA few additional arguments are available both for reading and writing files:\n\n#### Building NetworkX graph object from file\n\n```python\nG = read_gdf(\n \"input_file.gdf\",\n # Required; file path to read data from.\n\n directed=None,\n # Optional; consider edges as directed or undirected.\n # True: returns a <nx.DiGraph> or <nx.MultiDiGraph> object.\n # False: returns a <nx.Graph> or <nx.MultiGraph> object.\n # None (default): decides based on \"directed\" edge attribute in file.\n\n multigraph=None,\n # Optional; consider multiple or single edges among nodes.\n # True: always returns a <nx.MultiGraph> or <nx.MultiDiGraph> object.\n # False: sums edge weights and returns a <nx.Graph> or <nx.DiGraph> object.\n # None (default): decides based on number of edges among the same pair of nodes.\n\n node_attr=None,\n # Optional; node attributes to import data from.\n # Accepts either a list containing attribute names or a boolean (True, False).\n # Defaults to True, which considers all node attributes.\n\n edge_attr=None,\n # Optional; edge attributes to import data from.\n # Accepts either a list containing attribute names or a boolean (True, False).\n # Defaults to True, which considers all edge attributes.\n)\n```\n\n#### Writing NetworkX graph object to file\n\n```python\nwrite_gdf(\n G,\n # Required; graph object from NetworkX.\n\n \"output_file.gdf\",\n # Required; file path to write data to.\n\n node_attr=None,\n # Optional; node attributes to export data from.\n # Accepts either a list containing attribute names or a boolean (True, False).\n # Defaults to True, which considers all node attributes.\n\n edge_attr=None,\n # Optional; edge attributes to export data from.\n # Accepts either a list containing attribute names or a boolean (True, False).\n # Defaults to True, which considers all edge attributes.\n)\n```\n\nNote that any object types beyond integers/longs, floats/doubles, and booleans will be considered as strings.\n\n### Importing as a class\n\nAlternatively, the module can also be imported as a class and inherited:\n\n```python\nfrom networkx_gdf import GDF\n\nclass MyClass(GDF):\n ...\n\nG = MyClass.read_gdf(\"input_file.gdf\")\nMyClass.write_gdf(G, \"output_file.gdf\")\n```\n\nBoth functions are implemented as static methods, so initializing the class as an object is not required.\n\n___\n\n### References\n\n* [NetworkX](https://networkx.github.io)\n* [Pandas](https://pandas.pydata.org/)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python package to read and write NetworkX graphs as GDF (Graph Data Format).",
"version": "1.3.2",
"project_urls": {
"Homepage": "https://github.com/nelsonaloysio/networkx-gdf",
"Source": "https://github.com/nelsonaloysio/networkx-gdf",
"Tracker": "https://github.com/nelsonaloysio/networkx-gdf/issues"
},
"split_keywords": [
"network",
"graph",
"gdf"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "72dc1cda163e59470639a9b5817011e1d26f3ab3a67e13a253a412baba8e5b53",
"md5": "5654b143980c491e7765904e33fc24bb",
"sha256": "8870ba83e217b77e8ccbf9ca4d5c827dc8334689e8ccfbe15f5c2364651ad035"
},
"downloads": -1,
"filename": "networkx_gdf-1.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5654b143980c491e7765904e33fc24bb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5674,
"upload_time": "2024-02-16T22:15:58",
"upload_time_iso_8601": "2024-02-16T22:15:58.774366Z",
"url": "https://files.pythonhosted.org/packages/72/dc/1cda163e59470639a9b5817011e1d26f3ab3a67e13a253a412baba8e5b53/networkx_gdf-1.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3e4e8c55ff1a87859a37d262c2156731f71b99e8ef9ff03ff5d81013336f3e98",
"md5": "90cf6d944e1bb9fe44d2e590a14432fb",
"sha256": "4e923c6e19fc961ad2b078e3d079e6c3a1b9fd53554746258f9882f8f7a124ec"
},
"downloads": -1,
"filename": "networkx-gdf-1.3.2.tar.gz",
"has_sig": false,
"md5_digest": "90cf6d944e1bb9fe44d2e590a14432fb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5474,
"upload_time": "2024-02-16T22:16:00",
"upload_time_iso_8601": "2024-02-16T22:16:00.092706Z",
"url": "https://files.pythonhosted.org/packages/3e/4e/8c55ff1a87859a37d262c2156731f71b99e8ef9ff03ff5d81013336f3e98/networkx-gdf-1.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-16 22:16:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nelsonaloysio",
"github_project": "networkx-gdf",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "networkx",
"specs": [
[
">=",
"2.1"
]
]
},
{
"name": "pandas",
"specs": [
[
">=",
"1.1.0"
]
]
}
],
"lcname": "networkx-gdf"
}