Skip to main content

Aurora DSQL adapter for Tortoise ORM

Project description

Aurora DSQL Adapter for Tortoise ORM

GitHub License PyPI - Version Discord chat

An adapter for building Tortoise ORM applications with Amazon Aurora DSQL.

Requirements

  • Tortoise ORM: 0.25 or later
  • Python: 3.10 or later (installation guide)
  • AWS Credentials: Valid credentials configured for IAM database authentication. The adapter generates a new auth token for each connection.
  • Aerich (optional): 0.9.2 or later, if using Aerich for migrations

Getting Started

Install the adapter with your preferred async driver:

# asyncpg
pip install aurora-dsql-tortoise-orm[asyncpg]

# psycopg
pip install aurora-dsql-tortoise-orm[psycopg]

Configuration

Configure your connection using the DSQL engine:

TORTOISE_ORM = {
    "connections": {
        "default": {
            "engine": "aurora_dsql_tortoise.asyncpg",  # or "aurora_dsql_tortoise.psycopg"
            "credentials": {
                "host": "<cluster_id>.dsql.<region>.on.aws",
                "user": "admin",
            },
        }
    },
    "apps": {
        "models": {
            "models": ["your.models"],
            "default_connection": "default",
        }
    },
}

The adapter accepts all parameters supported by the underlying asyncpg or psycopg driver, as well as the Aurora DSQL Connector for Python.

Or use a connection URL (requires registering the backend first):

from aurora_dsql_tortoise import register_backends

register_backends()

TORTOISE_ORM = {
    "connections": {
        "default": "dsql+asyncpg://admin@<cluster_id>.dsql.<region>.on.aws/postgres"
    },
    "apps": {
        "models": {
            "models": ["your.models"],
            "default_connection": "default",
        }
    },
}

Defining Models

UUID primary keys are recommended for optimal performance with Aurora DSQL:

import uuid
from tortoise import fields
from tortoise.models import Model

class Owner(Model):
    id = fields.UUIDField(primary_key=True, default=uuid.uuid4)
    name = fields.CharField(max_length=100)

    class Meta:
        table = "owner"

Aerich Migrations

For database migrations with Aerich, include the compatibility module:

TORTOISE_ORM = {
    "connections": {"default": {...}},
    "apps": {
        "models": {
            "models": [
                "your.models",
                "aerich.models",
                "aurora_dsql_tortoise.aerich_compat",
            ],
            "default_connection": "default",
        }
    },
}

The compatibility module patches Aerich to:

  • Use UUID primary keys for migration tracking
  • Execute DDL statements individually (DSQL transactions support only one DDL statement)

Features and Limitations

  • Adapter Behavior - How the adapter modifies Tortoise ORM behavior for Aurora DSQL compatibility
  • Known Issues - Known limitations and workarounds

Development

Install uv, then:

git clone https://github.com/awslabs/aurora-dsql-orms
cd aurora-dsql-orms/python/tortoise-orm
uv sync

Running Tests

⚠️ Running integration tests may result in charges to your AWS account.

Unit tests:

uv run unit

Integration tests (requires a DSQL cluster):

cp .env.example .env
# Edit .env with your cluster endpoint
uv run integration

Getting Help

Additional Resources

Opening Issues

If you encounter a bug, please search existing issues before opening a new one. GitHub issues are intended for bug reports and feature requests.

License

This library is licensed under the Apache 2.0 License.

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

aurora_dsql_tortoise_orm-0.2.0.tar.gz (77.9 kB view details)

Uploaded Source

Built Distribution

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

aurora_dsql_tortoise_orm-0.2.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file aurora_dsql_tortoise_orm-0.2.0.tar.gz.

File metadata

  • Download URL: aurora_dsql_tortoise_orm-0.2.0.tar.gz
  • Upload date:
  • Size: 77.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aurora_dsql_tortoise_orm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3ecb66484292ef3f251c976f0cf6de6be1a9df704229959f035be5efb91457c4
MD5 5a3b11fd9e50a8c4db1fbdfc3bd61fed
BLAKE2b-256 68290a9e8131b114fa2d8072b8cb079a07fd0ea215323d8a31c0859fd1382297

See more details on using hashes here.

Provenance

The following attestation bundles were made for aurora_dsql_tortoise_orm-0.2.0.tar.gz:

Publisher: python-tortoise-release.yml on awslabs/aurora-dsql-orms

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aurora_dsql_tortoise_orm-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aurora_dsql_tortoise_orm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ffc29723b2632d65bcabd612f3cc7a6386b52ae0696b30ebb3036013aad76ff
MD5 b6d310ee4473f9f725213b06091c90c6
BLAKE2b-256 3d64a609e664611d1c4ee88cca4b66064e0119d84ffc0ab078ff0baaae11bc16

See more details on using hashes here.

Provenance

The following attestation bundles were made for aurora_dsql_tortoise_orm-0.2.0-py3-none-any.whl:

Publisher: python-tortoise-release.yml on awslabs/aurora-dsql-orms

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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