mypy-boto3-freetier
mypy-boto3-freetier provides type annotations (type stubs) for the boto3 FreeTier service, enhancing developer experience with static type checking in Python projects. It is part of the larger `mypy-boto3` ecosystem, generated by `mypy-boto3-builder`, and its versions typically align with corresponding `boto3` releases, with frequent updates to reflect AWS service changes.
Warnings
- breaking Python 3.8 is no longer supported for `mypy-boto3-builder` generated packages (including `mypy-boto3-freetier`) as of `mypy-boto3-builder` version 8.12.0.
- gotcha `mypy-boto3-freetier` is a stub-only package. It provides type hints for `boto3` but does not include `boto3` itself. `boto3` must be installed separately to provide the runtime functionality.
- gotcha For optimal type checking accuracy, ensure the version of `mypy-boto3-freetier` closely matches your installed `boto3` version. Significant version mismatches can lead to incorrect or missing type hints.
- gotcha The AWS FreeTier service only exposes a client interface. Attempting to use `boto3.resource('freetier')` will result in a runtime error from boto3, as there is no FreeTier resource.
Install
-
pip install mypy-boto3-freetier boto3
Imports
- FreeTierClient
from mypy_boto3_freetier.client import FreeTierClient
- FreeTierServiceResource
import boto3 # FreeTier does not have a resource interface, so this import path is not available.
- GetFreeTierUsageResponseTypeDef
from mypy_boto3_freetier.type_defs import GetFreeTierUsageResponseTypeDef
Quickstart
import boto3
from mypy_boto3_freetier.client import FreeTierClient
from mypy_boto3_freetier.type_defs import GetFreeTierUsageResponseTypeDef
def get_freetier_usage() -> GetFreeTierUsageResponseTypeDef:
# mypy-boto3-freetier provides type hints for this client
client: FreeTierClient = boto3.client('freetier')
response: GetFreeTierUsageResponseTypeDef = client.get_free_tier_usage()
print(f"Free Tier Usage: {response.get('FreeTierUsages')}")
return response
if __name__ == '__main__':
# Ensure AWS credentials are configured or available via environment variables
# For local testing, you might need to mock boto3 or ensure credentials are set.
# Example: os.environ['AWS_ACCESS_KEY_ID'] = '...'
# os.environ['AWS_SECRET_ACCESS_KEY'] = '...'
# os.environ['AWS_DEFAULT_REGION'] = 'us-east-1'
try:
get_freetier_usage()
except Exception as e:
print(f"Error fetching Free Tier usage: {e}")