Skip to main content

pydantic based ArangoDB ODM

Project description

Pydango - Asynchronous Pydantic ArangoDB ORM

pydangorm is a Python ORM (Object-Relational Mapping) system tailored for ArangoDB, a multi-model NoSQL database. It provides a Pythonic interface for defining models, constructing queries, and interacting with ArangoDB, abstracting away the direct complexities of database interactions.

Features

  • Model Definitions with pydantic(v1): Easily define and validate your database models using pydantic.

    • VertexModel
    • EdgeModel
  • Pythonic Query Building: Construct complex ArangoDB queries with a Pythonic API.

  • Session Management: Streamlined management of database sessions and connections.

  • Collection Management: Create indices, truncate collections, and perform other collection operations.

  • Asynchronous Support: Perform asynchronous database operations for optimized I/O-bound tasks.


Full Documentation

Installation

pip install pydangorm

Quick Start & Usage Examples

Defining Models

Using pydangorm, you can define vertex and edge models with ease:

import datetime
from typing import Annotated

from pydango import (
    EdgeModel,
    VertexModel,
    EdgeCollectionConfig,
    VertexCollectionConfig,
    Relation,
)
from pydango.indexes import PersistentIndex


class Visited(EdgeModel):
    rating: int
    on_date: datetime.date

    class Collection(EdgeCollectionConfig):
        name = "visited"
        indexes = [
            PersistentIndex(fields=["rating"]),
        ]


class LivesIn(EdgeModel):
    since: datetime.datetime

    class Collection(EdgeCollectionConfig):
        name = "lives_in"


class Person(VertexModel):
    name: str
    age: int
    lives_in: Annotated["City", Relation[LivesIn]]
    visited: Annotated[list["City"], Relation[Visited]]

    class Collection(VertexCollectionConfig):
        name = "people"
        indexes = [
            PersistentIndex(fields=["name"]),
            PersistentIndex(fields=["age"]),
        ]


class City(VertexModel):
    name: str
    population: int

    class Collection(VertexCollectionConfig):
        name = "cities"
        indexes = [
            PersistentIndex(fields=["name"]),
            PersistentIndex(fields=["population"]),
        ]

Querying Data

Construct and execute queries in a Pythonic manner:

from aioarango import ArangoClient
from app.models import Person, City, Visited, LivesIn

from pydango import PydangoSession
from pydango.orm import for_
from pydango.connection.utils import get_or_create_db, deplete_cursor

person = Person(
    name="John",
    age=35,
    lives_in=City(name="Buenos Aires", population=30000000),
    visited=[
        City(name="Amsterdam", population=123),
        City(name="New Delhi", population=123),
    ],
    edges={
        Person.lives_in: LivesIn(since=datetime.datetime.now()),
        Person.visited: [
            Visited(rating=10, on_date=datetime.date.today()),
            Visited(rating=10, on_date=datetime.date.today()),
        ],
    },
)


async def main():
    db = await get_or_create_db(ArangoClient(), "app")
    session = PydangoSession(database=db)
    # Retrieving users older than 10 years
    await session.save(person)
    assert person.id.startswith("people/")

    db_person = await session.get(Person, person.key, fetch_edges=True, depth=(1, 1))
    assert db_person == person

    query = for_(Person).filter(Person.age > 10).sort(-Person.age).return_(Person)
    query_result = await session.execute(query)
    result = await deplete_cursor(query_result)

More detailed examples and scenarios can be found in the tests directory, which showcases modeling and querying for different use-cases like cities, families, and e-commerce operations.

Detailed Documentation

For detailed documentation, please refer to the documentation.

Contributing

Contributions to pydangorm are welcome! Please refer to the CONTRIBUTING.md file for guidelines.

License

pydangorm is licensed under MIT. See the LICENSE file for 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

pydangorm-0.3.0.tar.gz (37.1 kB view details)

Uploaded Source

Built Distribution

pydangorm-0.3.0-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

File details

Details for the file pydangorm-0.3.0.tar.gz.

File metadata

  • Download URL: pydangorm-0.3.0.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pydangorm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 00d580553e91b95e71faf31647634ca07f5e0038deec5ecf32a37082f9d01ab1
MD5 a2d3432cf53385117f766068a6b9972b
BLAKE2b-256 ba9b437bc1785f5eac0f4b8c2518d12cacd8b3fb3e38676908d2c521fdc07bf5

See more details on using hashes here.

File details

Details for the file pydangorm-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pydangorm-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 46.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pydangorm-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6de3498347b4943361d14ae4bb4048a667fa30a9a04b90c68d51bb74fd9da8f5
MD5 6a05c62e850bcc6885b10afc9861346c
BLAKE2b-256 a8863ff9988f8da2cd921927fe25d753dd89b325dc93390f595f2a2fd0420b76

See more details on using hashes here.

Supported by

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