mypy-boto3-elbv2
mypy-boto3-elbv2 provides static type annotations for the boto3 ElasticLoadBalancingv2 (ELBv2) service, generated with mypy-boto3-builder 8.12.0. This package enhances developer experience by enabling type checking, autocompletion, and error detection in IDEs for boto3 clients, paginators, waiters, and type definitions related to AWS ELBv2. The current version is 1.42.3, and it follows the boto3 versioning with frequent updates to align with new AWS service features.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 or older must upgrade to Python 3.9 or newer.
- breaking Version 8.9.0 of `mypy-boto3-builder` introduced breaking changes in TypeDef naming conventions. Specifically, TypeDefs for packed method arguments use shorter names (`CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved to the end (`CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- gotcha For optimal IDE autocompletion and type checking, especially when using `mypy-boto3-elbv2` as a standalone package or `boto3-stubs-lite`, it is often necessary to explicitly annotate the client type (e.g., `client: ElasticLoadBalancingv2Client = boto3.client("elbv2")`). While `boto3-stubs` (the meta-package) aims for implicit type discovery, explicit annotations provide the most reliable experience.
- gotcha The version of `mypy-boto3-elbv2` is synchronized with the `boto3` version it provides stubs for (e.g., `mypy-boto3-elbv2 1.42.3` corresponds to `boto3 1.42.3`). Ensure your `mypy-boto3-elbv2` version matches or is compatible with your installed `boto3` version to avoid type checking inconsistencies.
- deprecated The original `mypy-boto3` top-level package is considered legacy. While `mypy-boto3-elbv2` (the service-specific stub) is still actively maintained and generated by `mypy-boto3-builder`, users are encouraged to use the `boto3-stubs` or `types-boto3` packages (e.g., `pip install 'boto3-stubs[elbv2]'`) for a more consolidated and officially recommended approach to type annotations.
Install
-
pip install mypy-boto3-elbv2 -
pip install 'boto3-stubs[elbv2]'
Imports
- ElasticLoadBalancingv2Client
from mypy_boto3_elbv2.client import ElasticLoadBalancingv2Client
- DescribeLoadBalancersOutputTypeDef
from mypy_boto3_elbv2.type_defs import DescribeLoadBalancersOutputTypeDef
Quickstart
import boto3
from mypy_boto3_elbv2.client import ElasticLoadBalancingv2Client
from mypy_boto3_elbv2.type_defs import DescribeLoadBalancersOutputTypeDef
def get_elbv2_client() -> ElasticLoadBalancingv2Client:
"""Returns a typed ELBv2 client."""
# boto3-stubs provides auto-discovery for Session.client
# For standalone mypy-boto3-elbv2, explicit typing is recommended.
client: ElasticLoadBalancingv2Client = boto3.client("elbv2")
return client
def list_load_balancers():
client = get_elbv2_client()
try:
response: DescribeLoadBalancersOutputTypeDef = client.describe_load_balancers()
for lb in response.get("LoadBalancers", []):
print(f"Load Balancer ARN: {lb['LoadBalancerArn']}, Name: {lb['LoadBalancerName']}")
except client.exceptions.LoadBalancerNotFoundException:
print("No load balancers found.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
list_load_balancers()