mypy-boto3-forecastquery Type Stubs

1.42.3 · active · verified Sat Apr 11

mypy-boto3-forecastquery provides static type annotations for the AWS Boto3 ForecastQueryService client, enhancing development with autocompletion, type checking, and improved code readability in IDEs and static analysis tools like MyPy and Pyright. It is generated by the mypy-boto3-builder project and is currently at version 1.42.3, typically updated in sync with Boto3 releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted ForecastQueryService client using `mypy-boto3-forecastquery` and perform a `query_forecast` operation. The `if TYPE_CHECKING:` block ensures that `mypy-boto3-forecastquery` remains a development-only dependency.

import boto3
from typing import TYPE_CHECKING
from mypy_boto3_forecastquery.type_defs import QueryForecastResponseTypeDef

if TYPE_CHECKING:
    from mypy_boto3_forecastquery.client import ForecastQueryServiceClient


def get_forecast_query_client() -> 'ForecastQueryServiceClient':
    """Returns a typed ForecastQueryService client."""
    return boto3.client("forecastquery")


def main():
    client = get_forecast_query_client()
    try:
        response: QueryForecastResponseTypeDef = client.query_forecast(
            ForecastArn='arn:aws:forecast:us-east-1:123456789012:forecast/my-forecast-name',
            StartDate='2023-01-01T00:00:00Z',
            EndDate='2023-01-07T00:00:00Z',
            Filters={'item_id': 'item_abc'}
        )
        print("Forecast data retrieved:")
        for item in response.get('Forecast', {}).get('Predictions', {}).get('mean', []):
            print(f"  Timestamp: {item['Timestamp']}, Value: {item['Value']}")
    except client.exceptions.ResourceNotFoundException:
        print("Forecast not found. Ensure ARN and filters are correct.")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    # Replace with a valid Forecast ARN and region for actual execution
    # os.environ['AWS_ACCESS_KEY_ID'] = 'YOUR_ACCESS_KEY'
    # os.environ['AWS_SECRET_ACCESS_KEY'] = 'YOUR_SECRET_KEY'
    # os.environ['AWS_REGION'] = 'us-east-1'
    main()

view raw JSON →