mypy-boto3-mq
mypy-boto3-mq provides type annotations for the AWS Boto3 MQ service client, enabling static type checking with tools like mypy, Pyright, and enhanced IDE autocompletion for `boto3.client('mq')`. It is a standalone stub package generated by the `mypy-boto3-builder` tool. The version (1.42.3) aligns with the corresponding `boto3` version, ensuring compatibility, and it is actively maintained with updates mirroring new `boto3` releases.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generates `mypy-boto3-mq`), Python 3.8 is no longer supported. Projects requiring Python 3.8 should use older versions of `mypy-boto3-mq` or upgrade their Python interpreter.
- breaking The `mypy-boto3-builder` (from version 8.12.0) migrated to PEP 561 compliant packaging. While generally beneficial, this change could potentially affect stub discovery in environments using older or non-standard build systems.
- breaking With `mypy-boto3-builder` version 8.9.0, type definition naming conventions were changed. Specifically, TypeDefs for packed method arguments use shorter names, and conflicting TypeDef `Extra` postfixes were moved to the end. If your code explicitly imported or referenced these generated TypeDefs by their full names, it will break.
- gotcha PyCharm users might experience slow performance with Literal overloads in type hints. The `boto3-stubs-lite` package is recommended as a workaround until the upstream PyCharm issue (PY-40997) is resolved. This generally applies to all `mypy-boto3` generated stubs.
- gotcha When using `TYPE_CHECKING` guards to avoid runtime dependencies, Pylint might report 'undefined variable' errors for the type-hinted objects.
Install
-
pip install mypy-boto3-mq boto3
Imports
- MQClient
from mypy_boto3_mq import MQClient import boto3 client: MQClient = boto3.client("mq") - ListBrokersResponseTypeDef
from mypy_boto3_mq.type_defs import ListBrokersResponseTypeDef
Quickstart
import boto3
from mypy_boto3_mq import MQClient
from mypy_boto3_mq.type_defs import ListBrokersResponseTypeDef
import os
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# For example, by setting AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
# os.environ['AWS_REGION'] = os.environ.get('AWS_REGION', 'us-east-1')
def list_mq_brokers() -> None:
client: MQClient = boto3.client("mq")
try:
# Example: List Amazon MQ brokers
response: ListBrokersResponseTypeDef = client.list_brokers()
brokers = response.get('BrokerSummaries', [])
if brokers:
print("Amazon MQ Brokers found:")
for broker in brokers:
print(f" - Name: {broker.get('BrokerName')}, ARN: {broker.get('BrokerArn')}")
else:
print("No Amazon MQ brokers found.")
except client.exceptions.ClientError as e:
print(f"Error listing brokers: {e}")
if __name__ == "__main__":
list_mq_brokers()