mypy-boto3-apigateway Type Stubs

1.42.68 · active · verified Thu Apr 09

mypy-boto3-apigateway provides type annotations (stubs) for the boto3 APIGateway client and its associated data structures. It's part of the `mypy-boto3` ecosystem, generated by `mypy-boto3-builder`, aiming to enhance type-checking for `boto3` users. The library is actively maintained with frequent updates, often aligning with new `boto3` and AWS API releases. The current version is 1.42.68.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an APIGateway client with `boto3` and apply type hints using `mypy-boto3-apigateway`. It shows how to use generated `TypedDict` for both request parameters and response objects, enabling `mypy` to validate API calls.

import boto3
from mypy_boto3_apigateway.client import APIGatewayClient
from mypy_boto3_apigateway.type_defs import GetRestApisRequestRequestTypeDef, GetRestApisResponseTypeDef

# Configure AWS credentials if not using default profile/env vars
# import os
# os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', '')
# os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', '')
# os.environ['AWS_REGION'] = os.environ.get('AWS_REGION', 'us-east-1')

def list_apigateway_rest_apis() -> None:
    """Lists up to 10 APIGateway REST APIs and demonstrates type hinting."""
    # Type hint the client for static analysis
    client: APIGatewayClient = boto3.client("apigateway")

    # Use a TypedDict for request parameters, ensuring correct types and keys
    request_params: GetRestApisRequestRequestTypeDef = {
        "position": "0",
        "limit": 10
    }

    # The response is also a TypedDict, allowing safe attribute access
    response: GetRestApisResponseTypeDef = client.get_rest_apis(**request_params)

    print(f"Found {len(response.get('items', []))} REST APIs:")
    for item in response.get('items', []):
        name = item.get('name', 'N/A')
        api_id = item.get('id', 'N/A')
        print(f"- {name} (ID: {api_id})")

    # mypy would flag issues like:
    # print(response['non_existent_key']) # Error: Key 'non_existent_key' not found in GetRestApisResponseTypeDef

if __name__ == "__main__":
    list_apigateway_rest_apis()

view raw JSON →