Skip to main content

capo-rds: typed, async Python SDK for AWS RDS

capo-rds is a typed Python SDK for Amazon RDS and Aurora: connect to a database with an IAM authentication token instead of a password, and manage instances, clusters and snapshots. AsyncRDSClient works with asyncio and trio, and RDSClient has the same methods for sync code. Requests and responses are typed with TypedDicts, so your editor and type checker know every field.

It is part of capo, a community-driven alternative to boto3 and aioboto3, built on its own HTTP stack instead of botocore and generated from the official AWS Smithy models. Documentation: https://capo-sdk.dev/services/rds/

Install capo-rds

pip install capo-rds

Connect to an RDS database with IAM authentication

The instance needs IAM database authentication enabled, and the database user has to be set up for it: GRANT rds_iam TO app on PostgreSQL, CREATE USER app IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS' on MySQL. The credentials the client signs with need the rds-db:connect permission.

import asyncpg
from capo_rds import AsyncRDSClient

HOST = "mydb.123456789012.us-east-1.rds.amazonaws.com"


async def main():
    async with AsyncRDSClient(region="us-east-1") as rds:
        # The token is the password. It is signed locally with the client's
        # credentials, so nothing is sent to AWS, and it is valid for 15 minutes
        token = await rds.generate_db_auth_token(hostname=HOST, port=5432, username="app")

    # IAM authentication needs TLS
    conn = await asyncpg.connect(
        host=HOST, port=5432, user="app", password=token, database="postgres", ssl="require"
    )
    print(await conn.fetchval("SELECT current_user"))
    await conn.close()
import psycopg
from capo_rds import RDSClient

HOST = "mydb.123456789012.us-east-1.rds.amazonaws.com"


def main():
    # The sync client: the same method, without async and await
    with RDSClient(region="us-east-1") as rds:
        token = rds.generate_db_auth_token(hostname=HOST, port=5432, username="app")

    with psycopg.connect(
        host=HOST, port=5432, user="app", password=token, dbname="postgres", sslmode="require"
    ) as conn:
        print(conn.execute("SELECT current_user").fetchone())

Keep a connection pool authenticated with IAM tokens

import asyncpg
from capo_rds import AsyncRDSClient

HOST = "mydb.123456789012.us-east-1.rds.amazonaws.com"


async def main():
    async with AsyncRDSClient(region="us-east-1") as rds:
        # A token expires after 15 minutes, but a connection opened with it stays
        # open. asyncpg calls password for every new connection, so each one gets
        # a fresh token
        async with asyncpg.create_pool(
            host=HOST,
            port=5432,
            user="app",
            database="postgres",
            ssl="require",
            password=lambda: rds.generate_db_auth_token(hostname=HOST, port=5432, username="app"),
        ) as pool:
            print(await pool.fetchval("SELECT current_user"))

List RDS database instances

from capo_rds import AsyncRDSClient


async def main():
    async with AsyncRDSClient(region="us-east-1") as rds:
        # Every instance, however many pages that takes
        async for db in rds.iter_describe_db_instances():
            endpoint = db.get("endpoint", {})
            print(db.get("db_instance_identifier"), db.get("db_instance_status"), endpoint.get("address"))

        # One instance, by its identifier
        response = await rds.describe_db_instances(db_instance_identifier="mydb")
        for db in response.get("db_instances", []):
            print(db.get("engine"), db.get("engine_version"))

Create an RDS database with IAM authentication

from capo_rds import AsyncRDSClient


async def main():
    async with AsyncRDSClient(region="us-east-1") as rds:
        # RDS keeps the master password in Secrets Manager; the application
        # connects with IAM tokens instead
        response = await rds.create_db_instance(
            db_instance_identifier="mydb",
            engine="postgres",
            db_instance_class="db.t4g.micro",
            allocated_storage=20,
            master_username="postgres",
            manage_master_user_password=True,
            enable_iam_database_authentication=True,
        )
        print(response.get("db_instance", {}).get("db_instance_status"))

Stop, start and snapshot an RDS database

from capo_rds import AsyncRDSClient


async def main():
    async with AsyncRDSClient(region="us-east-1") as rds:
        await rds.create_db_snapshot(
            db_snapshot_identifier="mydb-before-upgrade", db_instance_identifier="mydb"
        )

        # A stopped instance starts again by itself after seven days
        await rds.stop_db_instance(db_instance_identifier="mydb")
        await rds.start_db_instance(db_instance_identifier="mydb")

Handle RDS errors

from capo_rds import AsyncRDSClient
from capo_rds.errors import DBInstanceNotFoundFault, ServiceError


async def main():
    async with AsyncRDSClient(region="us-east-1") as rds:
        # An error the API describes has its own class
        try:
            await rds.describe_db_instances(db_instance_identifier="no-such-db")
        except DBInstanceNotFoundFault as e:
            print(e.code, e.message)

        # Any error RDS returns; one without a class of its own is an UnknownServiceError
        except ServiceError as e:
            print(e.code, e.message)

Configure RDS retries

from capo_rds import AsyncRDSClient


async def main():
    async with AsyncRDSClient(region="us-east-1", retry_max_attempts=5) as rds:
        # Throttling, server errors and network failures are retried. Every call
        # of this client gets five attempts instead of the default three
        await rds.describe_db_instances()
from capo_rds import AsyncRDSClient


async def main():
    async with AsyncRDSClient(region="us-east-1") as rds:
        # No retries for this call
        await rds.describe_db_instances(config_overrides={"retry_max_attempts": 1})

Metadata

Release files for capo-rds 0.25.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for capo-rds 0.25.0
File Size Uploaded Provenance Actions
capo_rds-0.25.0.tar.gz 877.9 kB Without provenance Details for capo_rds-0.25.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for capo-rds 0.25.0
File Interpreter ABI Platform Actions
capo_rds-0.25.0-py3-none-any.whl Python 3 none any Details for capo_rds-0.25.0-py3-none-any.whl

Total release size: 2.6 MB

Release files / capo_rds-0.25.0.tar.gz

Download URL capo_rds-0.25.0.tar.gz
Size 877.9 kB
Tags Source
SHA-256 checksum
How to use checksums
856e280e72de9473c1badf64359418d1e2fcb6a1cb2a95e130737196b4908f38
BLAKE2b-256 checksum
How to use checksums
70338f8e75712091b6511bd46bcdd0d70ffc5ff27e844cfeb585410128f0b42c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / capo_rds-0.25.0-py3-none-any.whl

Download URL capo_rds-0.25.0-py3-none-any.whl
Size 1.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
926df2d75d5dcf391a363c411e4b29cbf236e1550d5f9a88e1dc4d8e9beb4c9b
BLAKE2b-256 checksum
How to use checksums
f440ebc0357821b7670e2cf13e63be7800fe0608fc13d2f44a7b4cb89c302687
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for capo-rds 0.25.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page