mypy-boto3-synthetics Type Stubs for AWS Synthetics
mypy-boto3-synthetics provides comprehensive type annotations for the AWS Synthetics service within the boto3 library. It enables static type checking with tools like MyPy and Pyright, enhancing developer experience with features such as auto-completion and early bug detection in IDEs like VSCode and PyCharm. The package, currently at version 1.42.3, is generated by mypy-boto3-builder and is actively maintained, with updates often aligned with boto3 releases.
Warnings
- breaking Starting with mypy-boto3-builder 8.12.0 (which generated mypy-boto3-synthetics 1.42.3), Python 3.8 is no longer supported. Projects must use Python 3.9 or newer.
- breaking mypy-boto3-builder 8.9.0 introduced breaking changes to TypeDef naming conventions, making names shorter (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). If you manually referenced these types, your code might break.
- gotcha The mypy-boto3 ecosystem migrated to PEP 561-compliant packages with builder 8.12.0. This change might require explicit installation of `mypy-boto3-synthetics` or `boto3-stubs[synthetics]` to ensure type checkers properly discover and use the stubs.
- gotcha When using standalone service packages like `mypy-boto3-synthetics` (or `boto3-stubs-lite`), explicit type annotations on `boto3.Session().client()` calls are recommended (`client: SyntheticsClient = session.client("synthetics")`) to ensure full IDE auto-completion and type checking capabilities.
- gotcha A service like `sms-voice` was deprecated and replaced by `pinpoint-sms-voice` in mypy-boto3-builder 8.11.0. While specific to another service, this highlights that service names can change, potentially requiring updates to your imports and client instantiation strings.
Install
-
pip install mypy-boto3-synthetics -
pip install 'boto3-stubs[synthetics]'
Imports
- SyntheticsClient
from mypy_boto3_synthetics.client import SyntheticsClient
- SyntheticsServiceName
from mypy_boto3_synthetics.literals import SyntheticsServiceName
- CreateCanaryRequestRequestTypeDef
from mypy_boto3_synthetics.type_defs import CreateCanaryRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_synthetics.client import SyntheticsClient
from mypy_boto3_synthetics.type_defs import GetCanaryResponseTypeDef
def get_synthetics_client() -> SyntheticsClient:
"""Returns a type-hinted AWS Synthetics client."""
session = boto3.Session()
client: SyntheticsClient = session.client("synthetics")
return client
if __name__ == "__main__":
synthetics_client = get_synthetics_client()
try:
canary_name = "my-test-canary"
response: GetCanaryResponseTypeDef = synthetics_client.get_canary(Name=canary_name)
print(f"Successfully retrieved canary '{canary_name}':")
print(response)
except synthetics_client.exceptions.NotFoundException:
print(f"Canary '{canary_name}' not found.")
except Exception as e:
print(f"An error occurred: {e}")