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, the multi-model database for graph & beyond, 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

Open In Collab

Also available as an ArangoDB Lunch & Learn session: Graph & Beyond Course #2.9

from arango import ArangoClient # Python-Arango driver
from networkx import grid_2d_graph # Sample graph from NetworkX

from adbnx_adapter import ADBNX_Adapter

# Let's assume that the ArangoDB "fraud detection" dataset is imported to this endpoint
db = ArangoClient(hosts="http://localhost:8529").db("_system", username="root", password="")

adbnx_adapter = ADBNX_Adapter(db)

# Use Case 1.1: ArangoDB to NetworkX via Graph name
nx_fraud_graph = adbnx_adapter.arangodb_graph_to_networkx("fraud-detection")

# Use Case 1.2: ArangoDB to NetworkX via Collection names
nx_fraud_graph_2 = adbnx_adapter.arangodb_collections_to_networkx(
    "fraud-detection", 
    {"account", "bank", "branch", "Class", "customer"}, # Vertex collections
    {"accountHolder", "Relationship", "transaction"} # Edge collections
)

# Use Case 1.3: 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)

# Use Case 2: 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

  1. git clone https://github.com/arangoml/networkx-adapter.git
  2. cd networkx-adapter
  3. (create virtual environment of choice)
  4. pip install -e .[dev]
  5. (create an ArangoDB instance with method of choice)
  6. 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


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-4.2.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

adbnx_adapter-4.2.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: adbnx_adapter-4.2.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for adbnx_adapter-4.2.0.tar.gz
Algorithm Hash digest
SHA256 56b576c47382f0995cb712bf9364fbfb50a55f14540565bd5ded463a6b1ad0a9
MD5 a66bfd6907cf9d8a088f88478f270dd4
BLAKE2b-256 e52ba029b7d7bc9c62509477c033f7d4902399f5e1b4ca454922caa492e7bbe8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for adbnx_adapter-4.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 842a6912ad3e03e48f9fac912b89fbf9f3366b07a1fd68eea23ed227b1c98203
MD5 02b1ca412de5f77b0a36b5c3185a3e2b
BLAKE2b-256 1066269bd5498f664a157c02c781e1151333e1ede2cfffaf0786c4d2c3a16373

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