Skip to content

Repository files navigation

Logo

CircleCICodeQLLast commit

PyPI version badgePython versions badge

LicenseCode style: blackDownloads

python-arango-async

Python driver for ArangoDB, a scalable multi-model database natively supporting documents, graphs and search.

This is the asyncio alternative of the python-arango driver.

Check out a demo app at python-arango-async-demo.

Requirements

  • ArangoDB version 3.11+
  • Python version 3.10+

Installation

pip install python-arango-async --upgrade

Getting Started

Here is a simple usage example:

fromarangoasyncimportArangoClientfromarangoasync.authimportAuthasyncdefmain():
# Initialize the client for ArangoDB.asyncwithArangoClient(hosts="http://localhost:8529") asclient:
auth=Auth(username="root", password="passwd")
# Connect to "_system" database as root user.sys_db=awaitclient.db("_system", auth=auth)
# Create a new database named "test".awaitsys_db.create_database("test")
# Connect to "test" database as root user.db=awaitclient.db("test", auth=auth)
# Create a new collection named "students".students=awaitdb.create_collection("students")
# Add a persistent index to the collection.awaitstudents.add_index(type="persistent", fields=["name"], options={"unique": True})
# Insert new documents into the collection.awaitstudents.insert({"name": "jane", "age": 39})
awaitstudents.insert({"name": "josh", "age": 18})
awaitstudents.insert({"name": "judy", "age": 21})
# Execute an AQL query and iterate through the result cursor.cursor=awaitdb.aql.execute("FOR doc IN students RETURN doc")
asyncwithcursor:
student_names= []
asyncfordocincursor:
student_names.append(doc["name"])

Another example with graphs:

asyncdefmain():
fromarangoasyncimportArangoClientfromarangoasync.authimportAuth# Initialize the client for ArangoDB.asyncwithArangoClient(hosts="http://localhost:8529") asclient:
auth=Auth(username="root", password="passwd")
# Connect to "test" database as root user.db=awaitclient.db("test", auth=auth)
# Get the API wrapper for graph "school".ifawaitdb.has_graph("school"):
graph=db.graph("school")
else:
graph=awaitdb.create_graph("school")
# Create vertex collections for the graph.students=awaitgraph.create_vertex_collection("students")
lectures=awaitgraph.create_vertex_collection("lectures")
# Create an edge definition (relation) for the graph.edges=awaitgraph.create_edge_definition(
edge_collection="register",
from_vertex_collections=["students"],
to_vertex_collections=["lectures"]
)
# Insert vertex documents into "students" (from) vertex collection.awaitstudents.insert({"_key": "01", "full_name": "Anna Smith"})
awaitstudents.insert({"_key": "02", "full_name": "Jake Clark"})
awaitstudents.insert({"_key": "03", "full_name": "Lisa Jones"})
# Insert vertex documents into "lectures" (to) vertex collection.awaitlectures.insert({"_key": "MAT101", "title": "Calculus"})
awaitlectures.insert({"_key": "STA101", "title": "Statistics"})
awaitlectures.insert({"_key": "CSC101", "title": "Algorithms"})
# Insert edge documents into "register" edge collection.awaitedges.insert({"_from": "students/01", "_to": "lectures/MAT101"})
awaitedges.insert({"_from": "students/01", "_to": "lectures/STA101"})
awaitedges.insert({"_from": "students/01", "_to": "lectures/CSC101"})
awaitedges.insert({"_from": "students/02", "_to": "lectures/MAT101"})
awaitedges.insert({"_from": "students/02", "_to": "lectures/STA101"})
awaitedges.insert({"_from": "students/03", "_to": "lectures/CSC101"})
# Traverse the graph in outbound direction, breath-first.query=""" FOR v, e, p IN 1..3 OUTBOUND 'students/01' GRAPH 'school' OPTIONS { order: 'bfs', uniqueVertices: 'global' } RETURN {vertex: v, edge: e, path: p} """asyncwithawaitdb.aql.execute(query) ascursor:
asyncfordocincursor:
print(doc)

Please see the documentation for more details.

About

The official ArangoDB async Python driver

Topics

Resources

Contributing

Security policy

Stars

15 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages