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:
from arangoasync import ArangoClient
from arangoasync.auth import Auth
async def main():
# Initialize the client for ArangoDB.
async with ArangoClient(hosts="http://localhost:8529") as client:
auth = Auth(username="root", password="passwd")
# Connect to "_system" database as root user.
sys_db = await client.db("_system", auth=auth)
# Create a new database named "test".
await sys_db.create_database("test")
# Connect to "test" database as root user.
db = await client.db("test", auth=auth)
# Create a new collection named "students".
students = await db.create_collection("students")
# Add a persistent index to the collection.
await students.add_index(type="persistent", fields=["name"], options={"unique": True})
# Insert new documents into the collection.
await students.insert({"name": "jane", "age": 39})
await students.insert({"name": "josh", "age": 18})
await students.insert({"name": "judy", "age": 21})
# Execute an AQL query and iterate through the result cursor.
cursor = await db.aql.execute("FOR doc IN students RETURN doc")
async with cursor:
student_names = []
async for doc in cursor:
student_names.append(doc["name"])
Another example with graphs:
async def main():
from arangoasync import ArangoClient
from arangoasync.auth import Auth
# Initialize the client for ArangoDB.
async with ArangoClient(hosts="http://localhost:8529") as client:
auth = Auth(username="root", password="passwd")
# Connect to "test" database as root user.
db = await client.db("test", auth=auth)
# Get the API wrapper for graph "school".
if await db.has_graph("school"):
graph = db.graph("school")
else:
graph = await db.create_graph("school")
# Create vertex collections for the graph.
students = await graph.create_vertex_collection("students")
lectures = await graph.create_vertex_collection("lectures")
# Create an edge definition (relation) for the graph.
edges = await graph.create_edge_definition(
edge_collection="register",
from_vertex_collections=["students"],
to_vertex_collections=["lectures"]
)
# Insert vertex documents into "students" (from) vertex collection.
await students.insert({"_key": "01", "full_name": "Anna Smith"})
await students.insert({"_key": "02", "full_name": "Jake Clark"})
await students.insert({"_key": "03", "full_name": "Lisa Jones"})
# Insert vertex documents into "lectures" (to) vertex collection.
await lectures.insert({"_key": "MAT101", "title": "Calculus"})
await lectures.insert({"_key": "STA101", "title": "Statistics"})
await lectures.insert({"_key": "CSC101", "title": "Algorithms"})
# Insert edge documents into "register" edge collection.
await edges.insert({"_from": "students/01", "_to": "lectures/MAT101"})
await edges.insert({"_from": "students/01", "_to": "lectures/STA101"})
await edges.insert({"_from": "students/01", "_to": "lectures/CSC101"})
await edges.insert({"_from": "students/02", "_to": "lectures/MAT101"})
await edges.insert({"_from": "students/02", "_to": "lectures/STA101"})
await edges.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}
"""
async with await db.aql.execute(query) as cursor:
async for doc in cursor:
print(doc)
Please see the documentation for more details.
Metadata
Release files for python-arango-async 1.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_arango_async-1.2.5.tar.gz | 264.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_arango_async-1.2.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 367.1 kB
Release files / python_arango_async-1.2.5.tar.gz
| Download URL | python_arango_async-1.2.5.tar.gz |
|---|---|
| Size | 264.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
603d00bea2432997b51e1b54b2bc25ca545b49da34ee9d518eb1a56ad792ea8e
|
|
BLAKE2b-256 checksum How to use checksums |
752397f4a0e49eb3af1007d594923c0f01ac8a3a24279b17522d4a51b9d5ce17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / python_arango_async-1.2.5-py3-none-any.whl
| Download URL | python_arango_async-1.2.5-py3-none-any.whl |
|---|---|
| Size | 102.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c1d824492da9c79daa917f71d46b809266f6b2eda9363e392172f7ad5a8afe0
|
|
BLAKE2b-256 checksum How to use checksums |
fb3061e9bc64f4a195b590de6ff7fcc3a0b84a5d076116a8dd1f59f29bd72b77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|