



Python-Arango
Python driver for ArangoDB, a scalable multi-model
database natively supporting documents, graphs and search.
Requirements
- ArangoDB version 3.11+
- Python version 3.9+
Installation
pip install python-arango --upgrade
Getting Started
Here is a simple usage example:
from arango import ArangoClient
client = ArangoClient(hosts="http://localhost:8529")
sys_db = client.db("_system", username="root", password="passwd")
sys_db.create_database("test")
db = client.db("test", username="root", password="passwd")
students = db.create_collection("students")
students.add_index({'type': 'persistent', 'fields': ['name'], 'unique': True})
students.insert({"name": "jane", "age": 39})
students.insert({"name": "josh", "age": 18})
students.insert({"name": "judy", "age": 21})
cursor = db.aql.execute("FOR doc IN students RETURN doc")
student_names = [document["name"] for document in cursor]
Another example with graphs:
from arango import ArangoClient
client = ArangoClient(hosts="http://localhost:8529")
db = client.db("test", username="root", password="passwd")
graph = db.create_graph("school")
eegraph = db.create_graph(
name="school",
smart=True)
students = graph.create_vertex_collection("students")
lectures = graph.create_vertex_collection("lectures")
edges = graph.create_edge_definition(
edge_collection="register",
from_vertex_collections=["students"],
to_vertex_collections=["lectures"]
)
students.insert({"_key": "01", "full_name": "Anna Smith"})
students.insert({"_key": "02", "full_name": "Jake Clark"})
students.insert({"_key": "03", "full_name": "Lisa Jones"})
lectures.insert({"_key": "MAT101", "title": "Calculus"})
lectures.insert({"_key": "STA101", "title": "Statistics"})
lectures.insert({"_key": "CSC101", "title": "Algorithms"})
edges.insert({"_from": "students/01", "_to": "lectures/MAT101"})
edges.insert({"_from": "students/01", "_to": "lectures/STA101"})
edges.insert({"_from": "students/01", "_to": "lectures/CSC101"})
edges.insert({"_from": "students/02", "_to": "lectures/MAT101"})
edges.insert({"_from": "students/02", "_to": "lectures/STA101"})
edges.insert({"_from": "students/03", "_to": "lectures/CSC101"})
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}
"""
cursor = db.aql.execute(query)
Please see the documentation for more details.