Mypy Boto3 WAFRegional Stubs
Provides static type annotations for the 'waf-regional' service of `boto3`, enabling robust type checking for AWS WAFRegional client interactions with tools like Mypy. This package is part of the `mypy-boto3` ecosystem, currently at version 1.42.3, and updates in sync with `boto3` releases via the `mypy-boto3-builder`.
Warnings
- breaking Python 3.8 support was removed from `mypy-boto3-builder` (and thus all generated stub packages) starting from version 8.12.0. Users on Python 3.8 must upgrade to Python 3.9 or newer.
- breaking Breaking changes to `TypeDef` naming conventions occurred in `mypy-boto3-builder` 8.9.0. If you directly imported and used generated `TypeDef`s, their names might have been shortened or rearranged (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).
- gotcha These `mypy-boto3-*` packages provide only type annotations for static analysis; they do not include the runtime functionality. You must also install the corresponding `boto3` (or `aioboto3` for async stubs) package for your application to run.
- gotcha The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages in `mypy-boto3-builder` 8.12.0. While this is primarily an internal change for package distribution, it might affect how some older build tools or specific `mypy` configurations locate and utilize type stubs.
Install
-
pip install mypy-boto3-waf-regional boto3
Imports
- WAFRegionalClient
from mypy_boto3_waf_regional import WAFRegionalClient
- ListRulesResponseTypeDef
from mypy_boto3_waf_regional.type_defs import ListRulesResponseTypeDef
Quickstart
import boto3
from mypy_boto3_waf_regional import WAFRegionalClient
from typing import TYPE_CHECKING
import os
# Ensure AWS region is set for boto3, e.g., via environment variable or ~/.aws/config
os.environ.setdefault('AWS_REGION', os.environ.get('AWS_REGION', 'us-east-1'))
if TYPE_CHECKING:
# This block is for static type checking only, not executed at runtime.
# 'client' will be type-checked as WAFRegionalClient.
client: WAFRegionalClient = boto3.client("waf-regional")
# Example of a type-checked API call; type checkers will validate arguments and response.
response = client.list_rules()
print(response.get('Rules')) # Type checker knows 'Rules' is a key here
else:
# This block runs at runtime. The type hint helps IDEs and linters.
client: WAFRegionalClient = boto3.client("waf-regional")
try:
# Attempt a non-destructive API call to demonstrate functionality.
response = client.list_rules()
print(f"Successfully listed WAFRegional rules: {len(response.get('Rules', []))} rules found.")
except Exception as e:
print(f"Error listing WAFRegional rules (check AWS credentials and region): {e}")
print("To run this code, ensure AWS credentials are configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION environment variables).")