Type Annotations for boto3 WAFV2
Type annotations for boto3 WAFV2 service, part of the `mypy-boto3` project. This project provides comprehensive type hints for `boto3` and `aioboto3` AWS SDKs, enhancing static analysis, IDE autocompletion, and catching type-related errors before runtime. It closely follows `botocore` updates, generating up-to-date service-specific stubs. The current version is 1.42.57, generated with `mypy-boto3-builder` 8.12.0.
Warnings
- breaking Python 3.8 support has been removed since `mypy-boto3-builder` version 8.12.0. All `mypy-boto3-*` packages now require Python 3.9 or newer.
- breaking The `mypy-boto3` project migrated to PEP 561 for package structure with `mypy-boto3-builder` 8.12.0. This changes how stub packages are distributed and might affect custom tooling or build processes that relied on the previous package layout.
- breaking Type definition (TypedDict) naming conventions were changed in `mypy-boto3-builder` 8.9.0. This can break code that explicitly references old TypeDef names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).
- gotcha When using `if TYPE_CHECKING:` guards to conditionally import type hints, Pylint might report undefined variables if the types are not explicitly assigned to `object` in the `else` branch. Mypy and other type checkers are generally fine without this.
Install
-
pip install mypy-boto3-wafv2 -
pip install 'boto3-stubs[wafv2]'
Imports
- WAFV2Client
from mypy_boto3_wafv2 import WAFV2Client
- WAFV2Client
from mypy_boto3_wafv2.client import WAFV2Client
- APIKeySummaryTypeDef
from mypy_boto3_wafv2.type_defs import APIKeySummaryTypeDef
- ActionValueType
from mypy_boto3_wafv2.literals import ActionValueType
Quickstart
import boto3
from typing import TYPE_CHECKING
from mypy_boto3_wafv2 import WAFV2Client
if TYPE_CHECKING:
# Only imported for type checking, not for runtime
pass
def get_wafv2_client() -> WAFV2Client:
# The boto3.client call is automatically typed by mypy-boto3
# if 'boto3-stubs' or 'mypy-boto3-wafv2' is installed.
client: WAFV2Client = boto3.client("wafv2")
return client
# Example usage (runtime functionality requires AWS credentials)
# client = get_wafv2_client()
# try:
# response = client.list_web_acls(Scope='CLOUDFRONT')
# print(response['WebACLs'])
# except Exception as e:
# print(f"Error listing Web ACLs: {e}")