mypy-boto3-forecast type stubs
This library provides type annotations (stubs) for `boto3`'s ForecastService, enabling static type checking with tools like MyPy. Its versioning closely tracks the corresponding `boto3` versions, ensuring compatibility with specific AWS API releases. It is actively maintained with frequent updates reflecting changes in the AWS Forecast service API.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-forecast` 1.42.3 and newer), Python 3.8 support has been removed. All generated stub packages now require Python 3.9 or higher.
- gotcha The version of `mypy-boto3-forecast` must ideally match the major and minor version of your installed `boto3` library to ensure accurate type checking. Mismatched versions can lead to incorrect type hints for new or deprecated API features.
- breaking Builder version 8.9.0 (affecting stub packages generated after this builder version) introduced breaking changes in how some TypeDef names are generated, favoring shorter names or resolving conflicts. Code explicitly referencing old, longer TypeDef names might break.
- gotcha Installing `mypy-boto3` (which includes stubs for all AWS services) alongside `mypy-boto3-forecast` (stubs for a single service) is redundant for the Forecast service. While usually harmless, it can increase installation size.
- gotcha These are type stubs and provide no runtime functionality. To benefit from `mypy-boto3-forecast`, you must explicitly run `mypy` (or another compatible type checker) on your codebase. The stubs do not alter `boto3`'s runtime behavior.
Install
-
pip install mypy-boto3-forecast boto3 mypy
Imports
- ForecastClient
from mypy_boto3_forecast.client import ForecastClient
- ForecastServiceResource
from mypy_boto3_forecast.service_resource import ForecastServiceResource
- ListDatasetsResponseTypeDef
from mypy_boto3_forecast.type_defs import ListDatasetsResponseTypeDef
Quickstart
import boto3
from mypy_boto3_forecast.client import ForecastClient
from mypy_boto3_forecast.type_defs import ListDatasetsResponseTypeDef
import os
# Ensure boto3 is configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME env vars)
# or ~/.aws/credentials and ~/.aws/config
# Create a typed boto3 client for Forecast
# The actual client is created by boto3.client, mypy-boto3 provides the type hint.
client: ForecastClient = boto3.client(
"forecast",
region_name=os.environ.get('AWS_REGION_NAME', 'us-east-1')
)
try:
# Example API call with type-hinted response
response: ListDatasetsResponseTypeDef = client.list_datasets(MaxResults=10)
print("Successfully listed Forecast datasets:")
for dataset in response.get('Datasets', []):
print(f"- {dataset.get('DatasetName', 'N/A')} (ARN: {dataset.get('DatasetArn', 'N/A')})")
except Exception as e:
print(f"Error listing datasets (check AWS credentials and permissions): {e}")
# In a real application, you might want to log the full exception details
# To type-check this code, save it as e.g. `forecast_app.py` and run:
# pip install mypy boto3 mypy-boto3-forecast
# mypy forecast_app.py