Convert Python-Graph-Objects between networkx, python-igraph and graph-tools.
Project description
pyintergraph
Convert Python-Graph-Objects between networkx, python-igraph and graph-tool.
Installation
This package can be installed via:
pip install pyintergraph
For the note on imports and dependencies, see the section at the bottom of the page.
Usage
import networkx as nx
import pyintergraph
nx_graph = nx.karate_club_graph()
graph_tool_graph = pyintergraph.nx2gt(nx_graph, labelname="node_label")
igraph_graph = pyintergraph.gt2igraph(graph_tool_graph, labelname="node_label")
reversed_nx_graph = pyintergraph.igraph2nx(igraph_graph)
# or
Graph = pyintergraph.InterGraph.from_networkx(nx_graph)
graph_tool_graph = Graph.to_graph_tool(labelname="node_label")
igraph_graph = Graph.to_igraph()
reversed_nx_graph = Graph.to_networkx()
assert list(nx_graph.nodes(data=True)) == list(reversed_nx_graph.nodes(data=True))
assert list(nx_graph.edges(data=True)) == list(reversed_nx_graph.edges(data=True))
assert type(nx_graph) == type(reversed_nx_graph)
A note on imports and dependencies
Because the installation of python-igraph and graph_tool can be tricky, they are not set as required dependencies for this package. As not everyone has all three packages installed, imports happen just when the two functions of interest are called. That way it is possible to convert networkX-Graphs to igraph-Graphs even when graph_tool is not installed.
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
Built Distribution
File details
Details for the file pyintergraph-1.3.3.tar.gz
.
File metadata
- Download URL: pyintergraph-1.3.3.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.0 CPython/3.12.0 Linux/6.5.11-300.fc39.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ba5396f497149d3179d400effd8ede5634ca3304ce7458ed350017f1cbe05fc |
|
MD5 | 5075dcb6446c18ec0cfece27b2064c00 |
|
BLAKE2b-256 | a6e7788d3652dc44fcaf2f05bee55505f1b4658510abb7346c09042cdd73dc08 |
File details
Details for the file pyintergraph-1.3.3-py3-none-any.whl
.
File metadata
- Download URL: pyintergraph-1.3.3-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.0 CPython/3.12.0 Linux/6.5.11-300.fc39.x86_64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15dbdf31659ded9fd0e1ee0155e7e7b8fbeae07b26794ef0bd260b3fdb32e861 |
|
MD5 | 37b9c8a0757bc499427814a08bf8248e |
|
BLAKE2b-256 | 6ba5e69102d4aca2414954e7e04ba8bd858fa66f6b839fd85bc8f0aa4359beb5 |