mypy-boto3-waf
mypy-boto3-waf provides type annotations for the AWS WAF service client in boto3, enabling static type checking with tools like Mypy. It is part of the mypy-boto3-builder project, which generates stubs for all boto3 services. The library is actively maintained, with version 1.42.3 available, and releases are frequent, typically aligned with updates to boto3 and the builder itself.
Warnings
- breaking Support for Python 3.8 has been officially removed starting from mypy-boto3-builder 8.12.0 (which generated mypy-boto3-waf 1.42.3). Users on Python 3.8 will need to upgrade their Python version to 3.9 or higher.
- breaking TypeDef naming conventions were changed in mypy-boto3-builder 8.9.0. TypeDefs for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`). Additionally, conflicting `Extra` postfixes were moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- gotcha The library migrated to PEP 561 compliance in mypy-boto3-builder 8.12.0. While this generally improves stub discovery for Mypy, users who previously configured custom `mypy_path` entries for `mypy-boto3` stubs might experience conflicts or incorrect stub loading. Mypy should now automatically discover these stubs if installed correctly.
Install
-
pip install mypy-boto3-waf
Imports
- WAFClient
from mypy_boto3_waf.client import WAFClient
- WAFServiceResource
from mypy_boto3_waf.service_resource import WAFServiceResource
- CreateWebACLRequestRequestTypeDef
from mypy_boto3_waf.type_defs import CreateWebACLRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_waf.client import WAFClient
def get_waf_webacls() -> None:
# mypy will now correctly type-check 'client'
client: WAFClient = boto3.client("waf")
try:
response = client.list_web_acls()
for web_acl in response.get("WebACLs", []):
print(f"WebACL Name: {web_acl['Name']}, ID: {web_acl['WebACLId']}")
except Exception as e:
print(f"Error listing WebACLs: {e}")
if __name__ == "__main__":
get_waf_webacls()