mypy-boto3-forecastquery Type Stubs
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
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-forecastquery` 1.42.3), support for Python 3.8 has been removed. Projects using this package must use Python 3.9 or newer. This release also migrated to PEP 561 compliant packages.
- breaking Version 8.9.0 of `mypy-boto3-builder` introduced breaking changes in TypeDef naming conventions (e.g., shorter names, repositioning of 'Extra' postfix). This may affect existing code that explicitly imports or refers to generated TypeDefs.
- gotcha It is crucial to install `mypy-boto3-forecastquery` alongside `boto3`. Without the stub package, IDEs and static type checkers cannot provide accurate autocompletion or type validation for `boto3`'s dynamically generated clients.
- gotcha PyCharm may experience slow performance or high CPU usage when handling `Literal` overloads within `mypy-boto3` packages.
- gotcha Using `if TYPE_CHECKING:` when importing types is a best practice to ensure `mypy-boto3-forecastquery` remains a development-only dependency. Without it, some linters (like Pylint) might complain about undefined variables or the type stub package could become a runtime dependency.
Install
-
pip install mypy-boto3-forecastquery boto3
Imports
- ForecastQueryServiceClient
from mypy_boto3_forecastquery.client import ForecastQueryServiceClient
- QueryForecastResponseTypeDef
from mypy_boto3_forecastquery.type_defs import QueryForecastResponseTypeDef
- ForecastQueryServiceName
from mypy_boto3_forecastquery.literals import ForecastQueryServiceName
Quickstart
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()