Mypy Boto3 WAFRegional Stubs

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

Demonstrates how to initialize a `boto3` WAFRegional client with type annotations and perform a simple API call. The `TYPE_CHECKING` block ensures type hints are only processed by static analyzers, while the `else` block provides runnable runtime code with basic error handling and region setup for `boto3`.

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).")

view raw JSON →