Skip to main content

Convert ArangoDB graphs to NetworkX & vice-versa.

Project description

ArangoDB-Networkx Adapter

build CodeQL Coverage Status Last commit

PyPI version badge Python versions badge

License Code style: black Downloads

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.

Quickstart

Get Started on Colab: Open In Colab

# Import the ArangoDB-NetworkX Adapter
from adbnx_adapter.adapter import ADBNX_Adapter

# Import a sample graph from NetworkX
from networkx import grid_2d_graph

# This is the connection information for your ArangoDB instance
# (Let's assume that the ArangoDB fraud-detection data dump is imported to this endpoint)
con = {
    "hostname": "localhost",
    "protocol": "http",
    "port": 8529,
    "username": "root",
    "password": "rootpassword",
    "dbName": "_system",
}

# This instantiates your ADBNX Adapter with your connection credentials
adbnx_adapter = ADBNX_Adapter(con)

# ArangoDB to NetworkX via Graph
nx_fraud_graph = adbnx_adapter.arangodb_graph_to_networkx("fraud-detection")

# ArangoDB to NetworkX via Collections
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
)

# ArangoDB to NetworkX via 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)

# 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 must be installed

  1. git clone https://github.com/arangoml/networkx-adapter.git
  2. cd networkx-adapter
  3. python -m venv .venv
  4. source .venv/bin/activate (MacOS) or .venv/scripts/activate (Windows)
  5. pip install -e .[dev]
  6. pytest

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

adbnx_adapter-3.0.0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

adbnx_adapter-3.0.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file adbnx_adapter-3.0.0.tar.gz.

File metadata

  • Download URL: adbnx_adapter-3.0.0.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for adbnx_adapter-3.0.0.tar.gz
Algorithm Hash digest
SHA256 f8719ec0baf5be42a0dd73b8703d21399b4b5447e4a0da07ff3db4fdb1355a85
MD5 ecf32721bc1000cba3b218d730234db6
BLAKE2b-256 81fed03cbd9c0ac9c1b195fc491989599c855c0a58b01c89a8ea940246349770

See more details on using hashes here.

File details

Details for the file adbnx_adapter-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: adbnx_adapter-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for adbnx_adapter-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8875d86d34d9b2678e32d6ed6fc3887457b4afd01ae8d230e214464e18756d0
MD5 574ed1411f69b6bdfc576eb1e6ccae54
BLAKE2b-256 9444657fc53ba96e0966e999ac1c3e1e5e36eafbb0b2c5cc980433966e5ffa8d

See more details on using hashes here.

Supported by

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