mypy-boto3-geo-places type annotations for AWS Location Service Places V2
This library provides comprehensive type annotations for the `boto3` AWS SDK, specifically for the Location Service Places V2. Generated by `mypy-boto3-builder`, it enhances developer experience by enabling static type checking with tools like Mypy and improving IDE features like autocompletion and error detection for `boto3` calls. The current version is 1.42.82, with releases typically synchronized with `boto3` updates and `mypy-boto3-builder` enhancements.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and subsequently for all generated `mypy-boto3` packages. Users must upgrade to Python 3.9 or newer.
- breaking TypeDef naming conventions were changed in `mypy-boto3-builder` 8.9.0. Some TypeDefs for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Conflicting `Extra` postfixes were also moved to the end.
- gotcha This package provides only type stubs and does not include the `boto3` runtime library. `boto3` must be installed separately to enable actual AWS API interactions.
- gotcha For optimal autocompletion and type checking in IDEs like VSCode, explicit type annotations for `boto3.client()` and `boto3.resource()` calls are often recommended, especially if the IDE's Python extension does not fully support function overloads.
- gotcha When using `mypy-boto3` packages with PyCharm, you might encounter slow performance or high CPU usage due to `Literal` overloads. It is recommended to try `boto3-stubs-lite` or disable PyCharm's internal type checker and use `mypy` or `pyright` instead.
Install
-
pip install mypy-boto3-geo-places boto3
Imports
- LocationServicePlacesV2Client
from mypy_boto3_geo_places.client import LocationServicePlacesV2Client
- SearchPlaceIndexForTextResponseTypeDef
from mypy_boto3_geo_places.type_defs import SearchPlaceIndexForTextResponseTypeDef
- PlacesIndexNameType
from mypy_boto3_geo_places.literals import PlacesIndexNameType
Quickstart
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_geo_places.client import LocationServicePlacesV2Client
from mypy_boto3_geo_places.type_defs import SearchPlaceIndexForTextResponseTypeDef
def search_places(index_name: str, text: str) -> SearchPlaceIndexForTextResponseTypeDef:
client: LocationServicePlacesV2Client = boto3.client("geo-places", region_name="us-east-1")
response: SearchPlaceIndexForTextResponseTypeDef = client.search_place_index_for_text(
IndexName=index_name,
Text=text
)
return response
# Example usage (will not run without actual AWS credentials and an index)
if __name__ == "__main__":
# Replace with your actual index name
my_index = "YOUR_PLACE_INDEX_NAME"
search_query = "coffee shop in New York"
try:
# Mock environment variables for demonstration, replace with actual if running
import os
os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY')
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET')
result = search_places(my_index, search_query)
print(f"Found {len(result['Results'])} places.")
for place in result['Results']:
print(f" Place: {place['Place']['Label']}")
except Exception as e:
print(f"An error occurred (expected without proper AWS setup): {e}")