Type Annotations for Boto3 B2BI
mypy-boto3-b2bi provides comprehensive type annotations for the AWS B2BI service client in `boto3`. It's part of the `mypy-boto3` collection, which generates type stubs for all `boto3` services, enhancing developer experience with static analysis and auto-completion. The current version is 1.42.3, and new versions are released frequently, typically mirroring `boto3` updates and `mypy-boto3-builder` releases.
Warnings
- breaking The `mypy-boto3-builder` (version 8.12.0, which generated mypy-boto3-b2bi 1.42.3) removed support for Python 3.8 and migrated to PEP 561 package standards. Projects still on Python 3.8 or relying on older package structures will encounter import or runtime errors.
- gotcha `mypy-boto3-b2bi` provides only type stubs. For the code to run, the actual `boto3` library must be installed. The stubs themselves do not include the AWS SDK functionality.
- gotcha Significant version mismatches between `boto3` and `mypy-boto3-b2bi` can lead to incorrect or missing type hints, as the stubs are generated to match specific `boto3` service definitions.
- breaking The `mypy-boto3-builder` (from version 8.9.0) introduced changes to generated TypeDef naming conventions (e.g., shorter names, altered postfix placement). While specific examples may not be for B2BI, direct reliance on exact TypeDef names from previous versions may break after an upgrade.
- deprecated Specific AWS services may be renamed or deprecated, leading to their corresponding `mypy-boto3-*` stub packages being updated or removed (e.g., `sms-voice` replaced by `pinpoint-sms-voice` in builder v8.11.0). While not directly impacting B2BI currently, this indicates a general risk for other services.
Install
-
pip install boto3 mypy-boto3-b2bi
Imports
- B2BIClient
from mypy_boto3_b2bi.client import B2BIClient
- paginate
from mypy_boto3_b2bi.paginator import ListPartnershipsPaginator
- waiter
from mypy_boto3_b2bi.waiter import SomeResourceExistsWaiter
Quickstart
import boto3
from mypy_boto3_b2bi import B2BIClient
from typing import Dict, Any
# The actual client comes from boto3. The B2BIClient type from mypy_boto3_b2bi
# is used to provide type hints for static analysis.
try:
# Assuming AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
client: B2BIClient = boto3.client("b2bi")
# Example operation: List Partnerships
# mypy will now validate the parameters and the structure of the response.
response = client.list_partnerships(
MaxResults=5 # Optional: limit the number of results
)
partnerships = response.get('partnerships', [])
print(f"Found {len(partnerships)} B2BI partnerships.")
for partnership in partnerships:
print(f" - Partnership ID: {partnership.get('partnershipId')}, Name: {partnership.get('name')}")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure 'boto3' and 'mypy-boto3-b2bi' are installed and AWS credentials are configured.")