mypy-boto3-mpa: Type Annotations for boto3 Multiparty Approval Service
mypy-boto3-mpa provides precise type annotations for the boto3 Multiparty Approval (MPA) service, generated by the `mypy-boto3-builder`. It helps improve code quality and catch type-related errors at development time when working with the AWS MPA API using boto3. The current version is 1.42.62, and releases are frequent, typically in sync with new boto3/botocore releases and AWS service updates.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and later, which affects all generated stub packages including `mypy-boto3-mpa`. Ensure your project uses Python 3.9 or newer.
- breaking The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages in version 8.12.0. While this improves discoverability for `mypy`, it might require updates to build systems or older `mypy` versions that relied on previous stub package structures. This also means packages are now `py.typed`.
- breaking In builder version 8.9.0, there were breaking changes to how TypeDefs for packed method arguments and conflicting names were generated. TypeDefs now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and conflicting `Extra` postfixes are moved to the end.
- gotcha `mypy-boto3-mpa` is a type stub package; it does not provide runtime functionality. It should not be imported as a regular library to instantiate clients or resources. Its purpose is solely for static type checking with tools like `mypy`.
- gotcha For optimal type checking, ensure that the version of `mypy-boto3-mpa` (and other `mypy-boto3-*` stubs) generally aligns with the version of `boto3` you are using. While minor mismatches often work, significant version differences can lead to incorrect type hints or missing definitions.
Install
-
pip install mypy-boto3-mpa boto3 mypy
Imports
- MPAClient
from mypy_boto3_mpa.client import MPAClient
- MPATypeDef
from mypy_boto3_mpa.type_defs import ApprovalRuleSummaryTypeDef
Quickstart
import boto3
from mypy_boto3_mpa.client import MPAClient
from mypy_boto3_mpa.type_defs import ListApprovalRulesOutputTypeDef
def get_mpa_rules() -> ListApprovalRulesOutputTypeDef:
# mypy-boto3-mpa provides type hints for the boto3 client
client: MPAClient = boto3.client("mpa")
# Replace with an actual operation that returns a list of rules
# For a real scenario, you'd call a valid MPA API operation.
response: ListApprovalRulesOutputTypeDef = client.list_approval_rules() # type: ignore
print(f"Found {len(response.get('ApprovalRules', []))} approval rules.")
return response
if __name__ == '__main__':
# This example requires boto3 and mypy-boto3-mpa to be installed.
# The 'type: ignore' comment is used because 'list_approval_rules'
# is a placeholder and might not exist or require specific parameters.
# In a real application, you would use actual MPA service methods.
try:
get_mpa_rules()
except Exception as e:
print(f"Could not fetch MPA rules (this is expected if the service method is a placeholder or not configured): {e}")