mypy-boto3-geo-routes Type Annotations
This library provides comprehensive type annotations for the AWS Boto3 LocationServiceRoutesV2 service. It is part of the mypy-boto3 project, which offers extensive stub packages for all boto3 services, generated by `mypy-boto3-builder`. The project is actively maintained, with new versions (currently 1.42.81) released frequently to align with upstream boto3 updates and AWS API changes.
Warnings
- breaking Python 3.8 support was removed for `mypy-boto3` packages with `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 will need to upgrade to Python 3.9 or newer to use current versions of these stubs.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` 8.9.0. Some TypeDef names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). This can break explicit type annotations in existing code.
- gotcha This package provides type stubs only. It requires the actual `boto3` library to be installed and configured for runtime execution. For optimal type checking and to avoid potential runtime issues, ensure your `mypy-boto3-geo-routes` stub version is compatible with your installed `boto3` version.
- gotcha The `mypy-boto3` packages migrated to PEP 561 standard distribution in builder version 8.12.0. While this is generally an improvement, some `mypy` configurations or build environments might require adjustments if issues with stub discovery arise after upgrading.
- gotcha When importing specific client or resource types, always import from the dedicated `mypy_boto3_SERVICE_NAME` package (e.g., `from mypy_boto3_location_service_routes_v2 import LocationServiceRoutesV2Client`). Do not attempt to import type hints directly from `boto3` modules, as they lack full type fidelity.
- gotcha AWS service names and their APIs can change or be deprecated over time (e.g., `sms-voice` service was renamed). While this package reflects the current state, always verify the service name used in `boto3.client()` and its corresponding `mypy-boto3` stub package name against the latest AWS documentation.
Install
-
pip install mypy-boto3-geo-routes
Imports
- LocationServiceRoutesV2Client
from mypy_boto3_location_service_routes_v2 import LocationServiceRoutesV2Client
- Service Type Definitions
from mypy_boto3_location_service_routes_v2.type_defs import CalculateRouteRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_location_service_routes_v2 import LocationServiceRoutesV2Client
from mypy_boto3_location_service_routes_v2.type_defs import CalculateRouteRequestRequestTypeDef
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# Initialize the boto3 client with type annotations
client: LocationServiceRoutesV2Client = boto3.client("location-service-routes-v2")
# Example: Calculate a route. Replace with actual data and coordinates.
# For a full list of parameters, refer to AWS Boto3 documentation.
request_params: CalculateRouteRequestRequestTypeDef = {
"CalculatorName": "ExampleRouteCalculator", # Must be an existing calculator name in your AWS account
"DeparturePosition": [10.0, 20.0], # Example: [longitude, latitude]
"DestinationPosition": [11.0, 21.0], # Example: [longitude, latitude]
"TravelMode": "Car",
"DepartureTime": "2024-01-01T00:00:00Z" # ISO 8601 format
}
try:
response = client.calculate_route(**request_params)
print(f"Calculated Route Summary: {response['Summary']}")
# Example output: Calculated Route Summary: {'DataSource': 'Esri', 'Distance': 1.23, 'DurationSeconds': 60.0}
except client.exceptions.ResourceNotFoundException as e:
print(f"Error: {e}. Ensure 'ExampleRouteCalculator' exists and is correctly configured in AWS Location Service.")
except Exception as e:
print(f"An unexpected error occurred: {e}")