Type annotations for boto3 RDS

1.42.75 · active · verified Sat Apr 11

types-boto3-rds provides static type annotations for the Amazon Relational Database Service (RDS) client in the `boto3` library. It enhances development experience by offering robust code completion, type checking, and error detection in IDEs and with static analysis tools like Mypy and Pyright. This package is generated by `mypy-boto3-builder` version 8.12.0 and currently aligns with `boto3` version 1.42.75, with frequent updates to match `boto3` releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted RDS client and use it to list DB instances, leveraging the type definitions provided by `types-boto3-rds`.

import boto3
from typing import TYPE_CHECKING, List
import os

if TYPE_CHECKING:
    from types_boto3_rds.client import RDSClient
    from types_boto3_rds.type_defs import DBInstanceTypeDef, DescribeDBInstancesOutputTypeDef

def get_typed_rds_client() -> "RDSClient":
    """Returns a type-hinted RDS client."""
    # AWS credentials typically managed by boto3's default credential chain
    # or environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION)
    # Example of setting region via environment variable for client creation:
    aws_region = os.environ.get('AWS_REGION', 'us-east-1')
    return boto3.client("rds", region_name=aws_region)

def list_db_instances_typed() -> List["DBInstanceTypeDef"]:
    """Lists all available DB instances with type hints."""
    rds_client: "RDSClient" = get_typed_rds_client()
    try:
        response: "DescribeDBInstancesOutputTypeDef" = rds_client.describe_db_instances()
        db_instances: List["DBInstanceTypeDef"] = response.get("DBInstances", [])
        print(f"Found {len(db_instances)} DB instances:")
        for instance in db_instances:
            print(f"- Identifier: {instance.get('DBInstanceIdentifier')}, Status: {instance.get('DBInstanceStatus')}, Engine: {instance.get('Engine')}")
        return db_instances
    except Exception as e:
        print(f"Error describing DB instances: {e}")
        return []

if __name__ == "__main__":
    # Set a dummy region for local testing if not already set
    if 'AWS_REGION' not in os.environ:
        os.environ['AWS_REGION'] = 'us-east-1'
    list_db_instances_typed()

view raw JSON →