Skip to main content

Python Driver for ArangoDB

Project description

Logo

CircleCI CodeQL Docs Coverage Status Last commit

PyPI version badge Python versions badge

License Code style: black Downloads

Python-Arango

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

If you're interested in using asyncio, please check python-arango-async.

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

# Initialize the client for ArangoDB.
client = ArangoClient(hosts="http://localhost:8529")

# Connect to "_system" database as root user.
sys_db = client.db("_system", username="root", password="passwd")

# Create a new database named "test".
sys_db.create_database("test")

# Connect to "test" database as root user.
db = client.db("test", username="root", password="passwd")

# Create a new collection named "students".
students = db.create_collection("students")

# Add a persistent index to the collection.
students.add_index({'type': 'persistent', 'fields': ['name'], 'unique': True})

# Insert new documents into the collection.
students.insert({"name": "jane", "age": 39})
students.insert({"name": "josh", "age": 18})
students.insert({"name": "judy", "age": 21})

# Execute an AQL query and iterate through the result cursor.
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

# Initialize the client for ArangoDB.
client = ArangoClient(hosts="http://localhost:8529")

# Connect to "test" database as root user.
db = client.db("test", username="root", password="passwd")

# Create a new graph named "school".
graph = db.create_graph("school")

# Create a new EnterpriseGraph [Enterprise Edition]
eegraph = db.create_graph(
    name="school",
    smart=True)

# Create vertex collections for the graph.
students = graph.create_vertex_collection("students")
lectures = graph.create_vertex_collection("lectures")

# Create an edge definition (relation) for the graph.
edges = graph.create_edge_definition(
    edge_collection="register",
    from_vertex_collections=["students"],
    to_vertex_collections=["lectures"]
)

# Insert vertex documents into "students" (from) vertex collection.
students.insert({"_key": "01", "full_name": "Anna Smith"})
students.insert({"_key": "02", "full_name": "Jake Clark"})
students.insert({"_key": "03", "full_name": "Lisa Jones"})

# Insert vertex documents into "lectures" (to) vertex collection.
lectures.insert({"_key": "MAT101", "title": "Calculus"})
lectures.insert({"_key": "STA101", "title": "Statistics"})
lectures.insert({"_key": "CSC101", "title": "Algorithms"})

# Insert edge documents into "register" edge collection.
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"})

# 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}
    """
cursor = db.aql.execute(query)

Please see the documentation for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_arango-8.2.0.tar.gz (153.2 kB view details)

Uploaded Source

Built Distribution

python_arango-8.2.0-py3-none-any.whl (114.8 kB view details)

Uploaded Python 3

File details

Details for the file python_arango-8.2.0.tar.gz.

File metadata

  • Download URL: python_arango-8.2.0.tar.gz
  • Upload date:
  • Size: 153.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for python_arango-8.2.0.tar.gz
Algorithm Hash digest
SHA256 be6a7b2a4d12912e54d2b8ede249935881367214e55fcfd47352de03df43c48c
MD5 7bfc514b54f2dc59fd273205e5c9c5b8
BLAKE2b-256 0208fffed4cd4ff1b991650da99fb0ea47f063b135cf45ab7ceea85c518f8e51

See more details on using hashes here.

File details

Details for the file python_arango-8.2.0-py3-none-any.whl.

File metadata

  • Download URL: python_arango-8.2.0-py3-none-any.whl
  • Upload date:
  • Size: 114.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for python_arango-8.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71ec7b67d6bedece4378f95d69b45d61c49d58376c23ca608025c84771333cb5
MD5 6d79dc4ccf3565cf710a263dd5f06fff
BLAKE2b-256 03e7057caa14bba50ae977283307602483f8507c7b4199bdaf805bb287a36d7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page