mypy-boto3-rds-data Type Annotations
mypy-boto3-rds-data provides comprehensive type annotations for the boto3 RDSDataService, enhancing static analysis, autocompletion, and type checking for AWS RDS Data API interactions in Python. This library, currently at version 1.42.3, is generated by the mypy-boto3-builder and offers compatibility with popular IDEs like VSCode and PyCharm, as well as type checkers such as Mypy and Pyright. New versions are released in sync with boto3 updates.
Warnings
- breaking Support for Python 3.8 has been removed. All `mypy-boto3-*` packages generated with `mypy-boto3-builder` version 8.12.0 or newer (including `mypy-boto3-rds-data 1.42.3`) require Python 3.9 or higher.
- breaking Type definition (TypeDef) names for packed method arguments have been shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Conflicting `Extra` postfixes were also moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`). While not specific to `rds-data`, this is a general breaking change from the underlying builder that might affect type hints for other services if specific TypeDefs are used directly.
- gotcha PyCharm users may experience slow performance or high CPU usage due to `Literal` overloads. It is recommended to use `boto3-stubs-lite` (if available for your service) or disable PyCharm's internal type checker and use `mypy` or `pyright` externally.
- gotcha For optimal autocompletion and type checking in IDEs like VSCode and PyCharm, explicit type annotations for `boto3.client` and `boto3.session.client` calls are highly recommended, as function overload support is not always fully robust.
- gotcha When using the `TYPE_CHECKING` flag to prevent production dependencies, Pylint might report 'undefined variable' errors. To fix this, set all types to `object` in the non-`TYPE_CHECKING` branch.
Install
-
pip install mypy-boto3-rds-data boto3 mypy
Imports
- RDSDataServiceClient
from mypy_boto3_rds_data.client import RDSDataServiceClient
- ArrayValueOutputTypeDef
from mypy_boto3_rds_data.type_defs import ArrayValueOutputTypeDef
- DecimalReturnTypeType
from mypy_boto3_rds_data.literals import DecimalReturnTypeType
Quickstart
import boto3
from typing import TYPE_CHECKING
from mypy_boto3_rds_data.client import RDSDataServiceClient
# Ensure boto3 is installed: pip install boto3 mypy-boto3-rds-data
def get_rds_data_client() -> RDSDataServiceClient:
if TYPE_CHECKING:
client: RDSDataServiceClient = boto3.client("rds-data")
else:
client = boto3.client("rds-data")
return client
def execute_statement(sql: str, database: str, resource_arn: str, secret_arn: str) -> None:
client = get_rds_data_client()
# Example: Execute SQL statement
response = client.execute_statement(
sql=sql,
database=database,
resourceArn=resource_arn,
secretArn=secret_arn,
includeResultMetadata=True
)
print("Statement executed.")
print(response)
# To run this, replace placeholders with actual AWS details:
# sql_query = "SELECT 1"
# db_name = "your_database_name"
# rds_resource_arn = "arn:aws:rds:region:account-id:cluster:cluster-name"
# rds_secret_arn = "arn:aws:secretsmanager:region:account-id:secret:secret-name"
# execute_statement(sql_query, db_name, rds_resource_arn, rds_secret_arn)