Skip to main content

Async Python Driver for ArangoDB

Project description

Logo

CircleCI CodeQL Last commit

PyPI version badge Python versions badge

License Code style: black Downloads

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 { bfs: true, 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.

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_async-1.0.6.tar.gz (258.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_arango_async-1.0.6-py3-none-any.whl (101.7 kB view details)

Uploaded Python 3

File details

Details for the file python_arango_async-1.0.6.tar.gz.

File metadata

  • Download URL: python_arango_async-1.0.6.tar.gz
  • Upload date:
  • Size: 258.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for python_arango_async-1.0.6.tar.gz
Algorithm Hash digest
SHA256 96565f9da5681a67ba0ebd941efa54c156477abeda8f8f445fa8b2098b6a0f1c
MD5 931d6a9fdb5c3540e748e32f3ab59d47
BLAKE2b-256 f0ca26381a1229495d674eea2be5fea5ab13689d0600ba0e3da81cd52468b600

See more details on using hashes here.

File details

Details for the file python_arango_async-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for python_arango_async-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4b4e3a3194b77188d819643d3c41418ee54368d4f5df3fdf5e05d2b9896c24ad
MD5 f07cf53ced3528a05949115fd54f7dc6
BLAKE2b-256 c6e660069b7eadb1bce148e5de5aa86ec86099a472f255252505888738e7039e

See more details on using hashes here.

Supported by

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