mypy-boto3-rds Type Annotations
mypy-boto3-rds provides type annotations for the AWS boto3 RDS service, enhancing static analysis and code completion for `boto3.client("rds")` and related service components. It is automatically generated by `mypy-boto3-builder` and aims to synchronize its version with the corresponding `boto3` release, offering up-to-date type hints for mypy, pyright, and various IDEs. The current version is 1.42.75, reflecting its alignment with `boto3`.
Warnings
- breaking Python 3.8 support has been explicitly removed in `mypy-boto3-builder` version 8.12.0 and subsequent releases. Users on Python 3.8 or older will not receive updates or new stubs.
- breaking Migration to PEP 561 compliant packages in `mypy-boto3-builder` 8.12.0. This might affect how type checkers locate stubs in complex environments or if you rely on older non-PEP 561 compliant patterns.
- breaking TypeDef naming conventions may change between major `mypy-boto3-builder` versions, leading to potential breaking changes if you directly import or refer to specific TypeDef names. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`.
- gotcha When using `mypy-boto3` stubs with linters like Pylint, you might encounter 'undefined variable' errors if you directly import stub classes without a runtime equivalent. This often happens because stubs are only for type-checking and not available at runtime.
- gotcha For optimal type checking, it is crucial to ensure that the version of `mypy-boto3-rds` (or `boto3-stubs`) installed matches or is compatible with the version of `boto3` you are using at runtime. Mismatched versions can lead to incorrect type hints or missing definitions.
Install
-
pip install mypy-boto3-rds -
pip install 'boto3-stubs[rds]'
Imports
- RDSClient
from mypy_boto3_rds.client import RDSClient
- DescribeDBInstancesMessageTypeDef
from mypy_boto3_rds.type_defs import DescribeDBInstancesMessageTypeDef
- DescribeDBInstancesPaginator
from mypy_boto3_rds.paginators import DescribeDBInstancesPaginator
Quickstart
import boto3
from typing import TYPE_CHECKING
# It is generally recommended to install 'boto3-stubs[rds]' for full integration.
# For explicit type annotation of the client:
if TYPE_CHECKING:
from mypy_boto3_rds.client import RDSClient
from mypy_boto3_rds.type_defs import DescribeDBInstancesMessageTypeDef
# Example of a Paginator
from mypy_boto3_rds.paginators import DescribeDBInstancesPaginator
# Initialize boto3 client
# For better type inference, explicitly annotate the client if TYPE_CHECKING is True
client: RDSClient = boto3.client("rds") if TYPE_CHECKING else boto3.client("rds")
try:
# Example API call with type-hinted response
response = client.describe_db_instances(
MaxRecords=20
)
# The 'response' object will have type hints based on DescribeDBInstancesMessageTypeDef
print(f"Found {len(response.get('DBInstances', []))} DB instances.")
# Example usage of a Paginator
paginator: DescribeDBInstancesPaginator = client.get_paginator("describe_db_instances")
for page in paginator.paginate():
print(f"Processing page with {len(page.get('DBInstances', []))} instances.")
except Exception as e:
print(f"An error occurred: {e}")