mypy-boto3-apigatewaymanagementapi Type Stubs

1.42.3 · active · verified Sat Apr 11

mypy-boto3-apigatewaymanagementapi provides type annotations for the `boto3` ApiGatewayManagementApi client. It helps developers write type-safe Python code when interacting with AWS API Gateway Management services, catching potential errors at development time rather than runtime. This library is currently at version 1.42.3 and is actively maintained with frequent releases tied to `boto3` updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an `ApiGatewayManagementApiClient` with type hints and make a sample call to `post_to_connection`. It highlights that `mypy-boto3` stubs provide compile-time type checking without altering `boto3`'s runtime behavior. Remember to provide a valid `endpoint_url` for `ApiGatewayManagementApi`.

import os
import boto3
from mypy_boto3_apigatewaymanagementapi.client import ApiGatewayManagementApiClient

# Initialize a boto3 client with type hints
# For local testing, ensure AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY are set.
# ApiGatewayManagementApi typically requires an endpoint_url.
client: ApiGatewayManagementApiClient = boto3.client(
    "apigatewaymanagementapi",
    region_name=os.environ.get("AWS_REGION", "us-east-1"),
    endpoint_url=os.environ.get("APIGATEWAY_MGMT_ENDPOINT_URL", "https://example.execute-api.us-east-1.amazonaws.com/prod")
)

# Example: Post data to a connection
try:
    connection_id = "some-connection-id"  # Replace with an actual connection ID
    data_to_send = b"Hello from mypy-boto3!"

    response = client.post_to_connection(
        ConnectionId=connection_id,
        Data=data_to_send
    )
    print(f"Successfully posted to connection {connection_id}. Response: {response}")
except client.exceptions.GoneException:
    print(f"Connection {connection_id} is gone.")
except Exception as e:
    print(f"An error occurred: {e}")

# Mypy will now validate client method calls and argument types:
# client.non_existent_method() # Mypy would flag this as an error

view raw JSON →