Skip to content

Commit

Permalink
new: 4.1.0 release prep (#84)
Browse files Browse the repository at this point in the history
* #83: initial commit

* Update README.md

* fix: flake8

* bump: python-arango version

* update notebook version
  • Loading branch information
aMahanna authored Jun 29, 2022
1 parent 89065a9 commit 3169aa4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,27 @@ pip install git+https://github.com/arangoml/networkx-adapter.git
Also available as an ArangoDB Lunch & Learn session: [Graph & Beyond Course #2.9](https://www.arangodb.com/resources/lunch-sessions/graph-beyond-lunch-break-2-9-introducing-the-arangodb-networkx-adapter/)

```py
# Import the ArangoDB-NetworkX Adapter
from adbnx_adapter import ADBNX_Adapter

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

# Import a sample graph from NetworkX
from networkx import grid_2d_graph
from adbnx_adapter import ADBNX_Adapter

# Instantiate driver client based on user preference
# Let's assume that the ArangoDB "fraud detection" dataset is imported to this endpoint for example purposes
# 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="")

# Instantiate your ADBNX Adapter with driver client
adbnx_adapter = ADBNX_Adapter(db)

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

# Convert ArangoDB to NetworkX via Collection Names
# 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"}, # Specify vertex collections
{"accountHolder", "Relationship", "transaction"} # Specify edge collections
{"account", "bank", "branch", "Class", "customer"}, # Vertex collections
{"accountHolder", "Relationship", "transaction"} # Edge collections
)

# Convert ArangoDB to NetworkX via a Metagraph
# Use Case 1.3: ArangoDB to NetworkX via Metagraph
metagraph = {
"vertexCollections": {
"account": {"Balance", "account_type", "customer_id", "rank"},
Expand All @@ -84,7 +78,7 @@ metagraph = {
}
nx_fraud_graph_3 = adbnx_adapter.arangodb_to_networkx("fraud-detection", metagraph)

# Convert NetworkX to ArangoDB
# Use Case 2: NetworkX to ArangoDB
nx_grid_graph = grid_2d_graph(5, 5)
adb_grid_edge_definitions = [
{
Expand Down
13 changes: 8 additions & 5 deletions adbnx_adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def arangodb_to_networkx(
attributes are included.
:type is_keep: bool
:param query_options: Keyword arguments to specify AQL query options when
fetching documents from the ArangoDB instance.
fetching documents from the ArangoDB instance. Full parameter list:
https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute
:type query_options: Any
:return: A Multi-Directed NetworkX Graph.
:rtype: networkx.classes.multidigraph.MultiDiGraph
Expand Down Expand Up @@ -159,7 +160,8 @@ def arangodb_collections_to_networkx(
:param e_cols: A set of edge collections to import to NetworkX.
:type e_cols: Set[str]
:param query_options: Keyword arguments to specify AQL query options when
fetching documents from the ArangoDB instance.
fetching documents from the ArangoDB instance. Full parameter list:
https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute
:type query_options: Any
:return: A Multi-Directed NetworkX Graph.
:rtype: networkx.classes.multidigraph.MultiDiGraph
Expand All @@ -181,7 +183,8 @@ def arangodb_graph_to_networkx(
:param name: The ArangoDB graph name.
:type name: str
:param query_options: Keyword arguments to specify AQL query options when
fetching documents from the ArangoDB instance.
fetching documents from the ArangoDB instance. Full parameter list:
https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute
:type query_options: Any
:return: A Multi-Directed NetworkX Graph.
:rtype: networkx.classes.multidigraph.MultiDiGraph
Expand Down Expand Up @@ -230,8 +233,8 @@ def networkx_to_arangodb(
Does not drop associated collections.
:type overwrite_graph: bool
:param import_options: Keyword arguments to specify additional
parameters for ArangoDB document insertion. See
arango.collection.Collection.import_bulk for all options.
parameters for ArangoDB document insertion. Full parameter list:
https://docs.python-arango.com/en/main/specs.html#arango.collection.Collection.import_bulk
:type import_options: Any
:return: The ArangoDB Graph API wrapper.
:rtype: arango.graph.Graph
Expand Down
18 changes: 11 additions & 7 deletions examples/ArangoDB_NetworkX_Adapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"id": "U1d45V4OeG89"
},
"source": [
"<a href=\"https://colab.research.google.com/github/arangoml/networkx-adapter/blob/4.0.0/examples/ArangoDB_NetworkX_Adapter.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/arangoml/networkx-adapter/blob/4.1.0/examples/ArangoDB_NetworkX_Adapter.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand All @@ -34,7 +34,7 @@
"id": "bpvZS-1aeG89"
},
"source": [
"Version: 4.0.0\n",
"Version: 4.1.0\n",
"\n",
"Objective: Export Graphs from [ArangoDB](https://www.arangodb.com/), a multi-model Graph Database, to [NetworkX](https://networkx.github.io/), the swiss army knife for graph analysis in python, and vice-versa."
]
Expand All @@ -57,8 +57,8 @@
"outputs": [],
"source": [
"%%capture\n",
"!git clone -b 4.0.0 --single-branch https://github.com/arangoml/networkx-adapter.git\n",
"!pip install adbnx-adapter==4.0.0\n",
"!git clone -b 4.1.0 --single-branch https://github.com/arangoml/networkx-adapter.git\n",
"!pip install adbnx-adapter==4.1.0\n",
"!pip install adb-cloud-connector\n",
"\n",
"# For drawing purposes\n",
Expand Down Expand Up @@ -478,7 +478,7 @@
"\n",
"# You can also provide valid Python-Arango AQL query options to the command above, like such:\n",
"# nx_g = adbnx_adapter.arangodb_graph_to_networkx(graph_name, ttl=1000, stream=True)\n",
"# See more here: https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute\n",
"# See the full parameter list at https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute\n",
"\n",
"# Show graph data\n",
"print('\\n--------------------')\n",
Expand Down Expand Up @@ -537,7 +537,7 @@
"\n",
"# You can also provide valid Python-Arango AQL query options to the command above, like such:\n",
"# nx_g = adbnx_adapter.arangodb_collections_to_networkx(\"fraud-detection\", vertex_collections, edge_collections, ttl=1000, stream=True)\n",
"# See more here: https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute\n",
"# See the full parameter list at https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute\n",
"\n",
"# Show graph data\n",
"print('\\n--------------------')\n",
Expand Down Expand Up @@ -608,7 +608,7 @@
"\n",
"# You can also provide valid Python-Arango AQL query options to the command above, like such:\n",
"# nx_g = adbnx_adapter.arangodb_to_networkx('fraud-detection', fraud_detection_metagraph, ttl=1000, stream=True)\n",
"# See more here: https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute\n",
"# See the full parameter list at https://docs.python-arango.com/en/main/specs.html#arango.aql.AQL.execute\n",
"\n",
"# Show graph data\n",
"print('\\n--------------------')\n",
Expand Down Expand Up @@ -785,6 +785,10 @@
"# Create the ArangoDB graph\n",
"grid_adb_g = adbnx_adapter.networkx_to_arangodb(name, grid_nx_g, edge_definitions)\n",
"\n",
"# You can also provide valid Python-Arango Import Bulk options to the command above, like such:\n",
"# grid_adb_g = adbnx_adapter.networkx_to_arangodb(name, grid_nx_g, edge_definitions, batch_size=5, on_duplicate=\"replace\")\n",
"# See the full parameter list at https://docs.python-arango.com/en/main/specs.html#arango.collection.Collection.import_bulk\n",
"\n",
"print('\\n--------------------')\n",
"print(\"URL: \" + con[\"url\"])\n",
"print(\"Username: \" + con[\"username\"])\n",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
license="Apache Software License",
install_requires=[
"requests>=2.27.1",
"python-arango>=7.4.0",
"python-arango>=7.4.1",
"networkx>=2.5.1",
"setuptools>=45",
],
Expand Down

0 comments on commit 3169aa4

Please sign in to comment.