mypy-boto3-dsql Type Annotations

1.42.3 · active · verified Sat Apr 11

This package provides machine-generated type annotations for the `boto3` AuroraDSQL service, specifically for `boto3` version 1.42.3. It's part of the `mypy-boto3-builder` ecosystem, designed to bring robust static type checking to `boto3` usage with `mypy`. The project maintains a frequent release cadence, often aligning with new `boto3` versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` DSQL client with `mypy-boto3-dsql` type annotations and execute a simple SQL statement. It highlights how the stubs provide type hints for client methods and their request/response `TypeDef` structures, improving code readability and catching potential errors at development time.

import boto3
from mypy_boto3_dsql.client import DSQLClient
from mypy_boto3_dsql.type_defs import ExecuteStatementRequestRequestTypeDef, ExecuteStatementResponseTypeDef
import os

# Configure AWS credentials and region via environment variables or ~/.aws/credentials
# For example, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION

def main():
    try:
        # mypy-boto3 stubs ensure type-hinting for boto3 clients
        client: DSQLClient = boto3.client("dsql", region_name=os.environ.get('AWS_REGION', 'us-east-1'))

        # Example request (adjust parameters as needed for your DSQL setup)
        request_params: ExecuteStatementRequestRequestTypeDef = {
            "dbClusterIdentifier": "your-db-cluster-identifier",
            "database": "your-database-name",
            "sql": "SELECT 1",
            "schema": "public",
            "continueAfterTimeout": False,
            "transactionIdentifier": "",
            "formatRecords": True
        }

        print("Executing DSQL statement...")
        response: ExecuteStatementResponseTypeDef = client.execute_statement(**request_params)

        print("Statement executed successfully!")
        print(f"Response Status: {response.get('responseMetadata', {}).get('HTTPStatusCode')}")
        if 'records' in response:
            print("Records returned:", response['records'])

    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    # Set dummy values if env vars are not present for demonstration purposes.
    # In a real scenario, these should be properly configured.
    os.environ.setdefault('AWS_ACCESS_KEY_ID', 'AKIAXXXXXXXXXXXXXXXX')
    os.environ.setdefault('AWS_SECRET_ACCESS_KEY', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
    os.environ.setdefault('AWS_REGION', 'us-east-1')
    main()

view raw JSON →