Type annotations for boto3 RDS
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
- breaking Python 3.8 support was removed for all `mypy-boto3-builder` generated packages, including `types-boto3-rds`, starting with builder version 8.12.0. The package now requires Python 3.9 or newer.
- breaking The `mypy-boto3-builder` (version 8.9.0) changed TypeDef naming conventions, potentially shortening names for packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`). If you were explicitly referencing the older, longer TypeDef names, your code may break.
- gotcha When using `mypy-boto3` type stubs (including `types-boto3-rds`) with Pylint, it might report undefined variables if types are imported directly. To avoid this and ensure compatibility in production environments where stubs are not installed, wrap type imports within a `typing.TYPE_CHECKING` block.
- gotcha PyCharm users might experience slow performance with Literal overloads in type stubs. For improved IDE performance, consider using the `types-boto3-lite` variants of the packages, which provide a more RAM-friendly experience at the cost of requiring more explicit type annotations.
- deprecated This library is the successor to `boto3-stubs`. If you are migrating from `boto3-stubs` or `mypy-boto3` packages, you need to replace `boto3-stubs` dependencies with `types-boto3` and adjust import paths from `mypy_boto3_<service>` to `types_boto3_<service>`.
Install
-
pip install types-boto3-rds -
pip install 'types-boto3[rds]' # Install via types-boto3 extras
Imports
- RDSClient
from types_boto3_rds.client import RDSClient
- DBInstanceTypeDef
from types_boto3_rds.type_defs import DBInstanceTypeDef
- DescribeDBInstancesOutputTypeDef
from types_boto3_rds.type_defs import DescribeDBInstancesOutputTypeDef
Quickstart
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()