Type Annotations for boto3 NetworkFirewall
mypy-boto3-network-firewall provides comprehensive type annotations for the AWS boto3 Network Firewall service (version 1.42.3). These type stubs are generated by mypy-boto3-builder (version 8.12.0) and enhance developer experience in IDEs like VSCode and PyCharm, as well as with static type checkers such as Mypy and Pyright. The library is actively maintained, with updates released in sync with new boto3 versions and improvements to the underlying builder.
Warnings
- breaking Support for Python 3.8 was removed in mypy-boto3-builder 8.12.0. As mypy-boto3-network-firewall 1.42.3 was generated with this builder version, it requires Python 3.9 or higher. Ensure your environment meets this requirement.
- breaking The `mypy-boto3-builder` (version 8.12.0) migrated to PEP 561 compliant packages. This change might affect how type checkers locate stubs in some environments or require a clean reinstall of stub packages.
- gotcha The version of `mypy-boto3-network-firewall` (e.g., 1.42.3) directly corresponds to the `boto3` and `botocore` version it provides stubs for, not the `mypy-boto3-builder` version. Ensure your installed `boto3` version is compatible with the `mypy-boto3-network-firewall` version for accurate type checking.
- breaking The `mypy-boto3-builder` (from version 8.9.0) introduced breaking changes to `TypeDef` naming conventions, such as shortening names for packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and moving the `Extra` postfix for conflicting names.
- gotcha When using `mypy-boto3` stubs with Pylint, if you employ `TYPE_CHECKING` guards to conditionally import types, Pylint might incorrectly report `undefined-variable` warnings for the type-hinted variables. This is a known issue with Pylint.
- gotcha While static type checkers like mypy and pyright can often infer types, some IDEs (especially older versions of VSCode with Pylance) might require explicit type annotations for `boto3.client`, `boto3.session.client`, `client.get_waiter`, and `client.get_paginator` calls to provide full autocomplete and type hinting.
Install
-
pip install mypy-boto3-network-firewall -
pip install 'boto3-stubs[network-firewall]' # Recommended for combined use with boto3-stubs
Imports
- NetworkFirewallClient
from mypy_boto3_network_firewall.client import NetworkFirewallClient
- NetworkFirewallServiceName
from mypy_boto3_network_firewall.literals import NetworkFirewallServiceName
- FirewallPolicyStatusType
from mypy_boto3_network_firewall.type_defs import FirewallPolicyStatusType
Quickstart
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_network_firewall.client import NetworkFirewallClient
def list_network_firewalls():
# The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are typically picked
# up from environment variables or AWS config files.
# Using os.environ.get for example purposes to avoid hardcoding credentials.
client: NetworkFirewallClient = boto3.client(
"network-firewall",
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
response = client.list_firewalls(
MaxResults=5 # Limit for demonstration
)
print("Found Firewalls:")
for firewall in response.get("Firewalls", []):
print(f" - {firewall.get('FirewallName')} ({firewall.get('FirewallArn')})")
if __name__ == "__main__":
import os
# Set dummy AWS credentials for local execution without actual AWS calls
# For actual execution, ensure valid credentials and region are configured.
os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'testing')
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'testing')
os.environ['AWS_SESSION_TOKEN'] = os.environ.get('AWS_SESSION_TOKEN', 'testing')
try:
list_network_firewalls()
except Exception as e:
print(f"An error occurred: {e}")