mypy-boto3-forecast type stubs

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This example demonstrates how to initialize a typed `boto3` Forecast client and make a simple API call. The `mypy-boto3-forecast` library adds static type hints, allowing tools like MyPy to catch potential issues before runtime. Remember to configure your AWS credentials for the code to run successfully.

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

view raw JSON →