Convert ArangoDB graphs to NetworkX & vice-versa.
Project description
ArangoDB-Networkx Adapter
The ArangoDB-Networkx Adapter exports Graphs from ArangoDB, a multi-model Graph Database, into NetworkX, the swiss army knife for graph analysis with python, and vice-versa.
About NetworkX
Networkx is a commonly used tool for analysis of network-data. If your analytics use cases require the use of all your graph data, for example, to summarize graph structure, or answer global path traversal queries, then using the ArangoDB Pregel API is recommended. If your analysis pertains to a subgraph, then you may be interested in getting the Networkx representation of the subgraph for one of the following reasons:
1. An algorithm for your use case is available in Networkx.
2. A library that you want to use for your use case works with Networkx Graphs as input.
Installation
Latest Release
pip install adbnx-adapter
Current State
pip install git+https://github.com/arangoml/networkx-adapter.git
Quickstart
For a more detailed walk-through, access the official notebook on Colab:
# Import the ArangoDB-NetworkX Adapter
from adbnx_adapter import ADBNX_Adapter
# Import the Python-Arango driver
from arango import ArangoClient
# Import a sample graph from NetworkX
from networkx import grid_2d_graph
# Instantiate driver client based on user preference
# Let's assume that the ArangoDB "fraud detection" dataset is imported to this endpoint for example purposes
db = ArangoClient(hosts="http://localhost:8529").db("_system", username="root", password="openSesame")
# Instantiate your ADBNX Adapter with driver client
adbnx_adapter = ADBNX_Adapter(db)
# Convert ArangoDB to NetworkX via Graph Name
nx_fraud_graph = adbnx_adapter.arangodb_graph_to_networkx("fraud-detection")
# Convert ArangoDB to NetworkX via Collection Names
nx_fraud_graph_2 = adbnx_adapter.arangodb_collections_to_networkx(
"fraud-detection",
{"account", "bank", "branch", "Class", "customer"}, # Specify vertex collections
{"accountHolder", "Relationship", "transaction"} # Specify edge collections
)
# Convert ArangoDB to NetworkX via a Metagraph
metagraph = {
"vertexCollections": {
"account": {"Balance", "account_type", "customer_id", "rank"},
"customer": {"Name", "rank"},
},
"edgeCollections": {
"transaction": {"transaction_amt", "sender_bank_id", "receiver_bank_id"},
"accountHolder": {},
},
}
nx_fraud_graph_3 = adbnx_adapter.arangodb_to_networkx("fraud-detection", metagraph)
# Convert NetworkX to ArangoDB
nx_grid_graph = grid_2d_graph(5, 5)
adb_grid_edge_definitions = [
{
"edge_collection": "to",
"from_vertex_collections": ["Grid_Node"],
"to_vertex_collections": ["Grid_Node"],
}
]
adb_grid_graph = adbnx_adapter.networkx_to_arangodb("Grid", nx_grid_graph, adb_grid_edge_definitions)
Development & Testing
Prerequisite: arangorestore
git clone https://github.com/arangoml/networkx-adapter.git
cd networkx-adapter
- (create virtual environment of choice)
pip install -e .[dev]
- (create an ArangoDB instance with method of choice)
pytest --url <> --dbName <> --username <> --password <>
Note: A pytest
parameter can be omitted if the endpoint is using its default value:
def pytest_addoption(parser):
parser.addoption("--url", action="store", default="http://localhost:8529")
parser.addoption("--dbName", action="store", default="_system")
parser.addoption("--username", action="store", default="root")
parser.addoption("--password", action="store", default="")
Project details
Release history Release notifications | RSS feed
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 adbnx_adapter-4.0.0.tar.gz
.
File metadata
- Download URL: adbnx_adapter-4.0.0.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4dab9c25c155dfdcb96e5bd8528d026c58b7ea0c92ddad1ffd1611b715bae3d |
|
MD5 | fec251e0dc760a71145971e81089b6fb |
|
BLAKE2b-256 | a9811581a9ba1065dd38e6a90adc69c2407257f18fdbb742c720c2608b1bb305 |
File details
Details for the file adbnx_adapter-4.0.0-py3-none-any.whl
.
File metadata
- Download URL: adbnx_adapter-4.0.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d651fa8e70a24bead069a12ac248b68f385c68ac01e804d5273f30a4321502e |
|
MD5 | a373632fadf04c38f46e2a2440a24f63 |
|
BLAKE2b-256 | 975e51793e556cd3990a484f1d92e46374e5c23c7da40c7a53ed8a4ec2dd236d |