mypy-boto3-apigatewaymanagementapi Type Stubs
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
- breaking As of `mypy-boto3-builder` version 8.12.0, all generated `mypy-boto3` packages (including `mypy-boto3-apigatewaymanagementapi`) officially removed support for Python 3.8. Projects now require Python >= 3.9.
- gotcha These stubs provide static type checking only; they do not alter `boto3`'s runtime behavior. You still need to install and use `boto3` as usual for your application to function.
- gotcha The `ApiGatewayManagementApi` client typically requires an `endpoint_url` parameter to specify the API Gateway's invocation URL (e.g., `https://{api_id}.execute-api.{region}.amazonaws.com/{stage}`). This is crucial for correctly routing requests to your specific API Gateway instance.
- gotcha To fully benefit from these type stubs, ensure `mypy` is installed in your development environment and configured to check your project. Run `mypy your_project_path` to enable type checking.
Install
-
pip install mypy-boto3-apigatewaymanagementapi -
pip install mypy-boto3
Imports
- ApiGatewayManagementApiClient
from mypy_boto3_apigatewaymanagementapi.client import ApiGatewayManagementApiClient
Quickstart
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