Type annotations for boto3 ServiceQuotas
mypy-boto3-service-quotas provides drop-in type annotations for the boto3 ServiceQuotas client. It enhances static type checking with tools like mypy and pyright, and improves autocompletion in IDEs such as VSCode and PyCharm, by leveraging type definitions extracted from botocore schemas. This package is generated automatically with mypy-boto3-builder and is currently at version 1.42.10, with frequent updates to align with new boto3 releases.
Warnings
- breaking Support for Python 3.8 was removed starting with `mypy-boto3-builder` version 8.12.0. Users must upgrade to Python 3.9 or newer.
- breaking Breaking changes in TypeDef naming conventions were introduced in `mypy-boto3-builder` 8.9.0. Type definitions for method arguments were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`).
- deprecated Individual AWS services may be deprecated or replaced by AWS. For example, `sms-voice` was replaced by `pinpoint-sms-voice`. While `service-quotas` has no known deprecation, always check the official AWS documentation for service lifecycle updates.
- gotcha When using `mypy-boto3-service-quotas` with PyCharm, you might experience slow performance due to PyCharm's handling of Literal overloads (issue PY-40997).
- gotcha If you use `TYPE_CHECKING` guards to avoid runtime dependency on `mypy-boto3-service-quotas`, `pylint` might complain about undefined variables. This is because `pylint` does not always respect `TYPE_CHECKING` in the same way type checkers do.
Install
-
pip install mypy-boto3-service-quotas boto3
Imports
- ServiceQuotasClient
from mypy_boto3_service_quotas.client import ServiceQuotasClient
- ListServiceQuotasOutputTypeDef
from mypy_boto3_service_quotas.type_defs import ListServiceQuotasOutputTypeDef
Quickstart
import os
from typing import TYPE_CHECKING
import boto3
# For runtime, boto3 client usually works without explicit import from stubs
# For type checking, import the specific client and type defs
if TYPE_CHECKING:
from mypy_boto3_service_quotas.client import ServiceQuotasClient
from mypy_boto3_service_quotas.type_defs import ListServiceQuotasOutputTypeDef
def get_service_quotas_client() -> "ServiceQuotasClient":
"""Returns a typed Service Quotas client."""
# This assumes AWS credentials are configured via environment variables,
# shared credentials file, or IAM role.
return boto3.client(
"service-quotas", region_name=os.environ.get("AWS_REGION", "us-east-1")
)
def list_quotas():
"""Lists service quotas and prints the first few."""
client = get_service_quotas_client()
try:
response: "ListServiceQuotasOutputTypeDef" = client.list_service_quotas(
ServiceCode="ec2" # Example service code, change as needed
)
quotas = response.get("Quotas", [])
if quotas:
print(f"Found {len(quotas)} EC2 quotas. First 3:")
for quota in quotas[:3]:
print(f"- {quota.get('QuotaName')}: {quota.get('Value')} {quota.get('Unit')}")
else:
print("No EC2 quotas found for 'ec2' service code.")
except Exception as e:
print(f"Error listing quotas: {e}")
if __name__ == "__main__":
# Set dummy AWS credentials for local testing without actual auth
# In a real scenario, these would be properly configured.
if "AWS_ACCESS_KEY_ID" not in os.environ:
os.environ["AWS_ACCESS_KEY_ID"] = os.environ.get("AWS_ACCESS_KEY_ID", "TEST_KEY")
os.environ["AWS_SECRET_ACCESS_KEY"] = os.environ.get("AWS_SECRET_ACCESS_KEY", "TEST_SECRET")
os.environ["AWS_SESSION_TOKEN"] = os.environ.get("AWS_SESSION_TOKEN", "TEST_TOKEN")
os.environ["AWS_REGION"] = os.environ.get("AWS_REGION", "us-east-1") # Required for many AWS calls
print("Attempting to list service quotas...")
list_quotas()