- Notifications
You must be signed in to change notification settings - Fork2
The official ArangoDB async Python driver
License
NotificationsYou must be signed in to change notification settings
arangodb/python-arango-async
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Python driver forArangoDB, a scalable multi-modeldatabase natively supporting documents, graphs and search.
This is theasyncio alternative of thepython-arangodriver.
Note: This project is still in active development, features might be added or removed.
- ArangoDB version 3.11+
- Python version 3.10+
pip install python-arango-async --upgrade
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 withgraphs:
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 { bfs: true, uniqueVertices: 'global' } RETURN {vertex: v, edge: e, path: p} """asyncwithawaitdb.aql.execute(query)ascursor:asyncfordocincursor:print(doc)
Please see thedocumentation for more details.
About
The official ArangoDB async Python driver
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.