{"id":3370,"library":"mypy-boto3-location","title":"Type Annotations for boto3 LocationService","description":"mypy-boto3-location provides type annotations for the boto3 LocationService, enhancing developer experience with type checking, autocomplete, and static analysis in IDEs like VSCode and PyCharm. It keeps pace with boto3 releases, automatically generating stubs with `mypy-boto3-builder`. The current version is 1.42.3.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","aws","type-hints","mypy","stubs","location"],"install":[{"cmd":"pip install mypy-boto3-location","lang":"bash","label":"Install standalone package"},{"cmd":"pip install 'boto3-stubs[location]' # Alternative using the bundled stubs","lang":"bash","label":"Install via boto3-stubs extras"}],"dependencies":[{"reason":"Provides the AWS SDK that these type stubs annotate.","package":"boto3","optional":false}],"imports":[{"symbol":"LocationServiceClient","correct":"from mypy_boto3_location.client import LocationServiceClient"},{"note":"For implicit typing, just `import boto3` is often sufficient, but explicit typing of the client is recommended for full IDE support and type checking.","symbol":"LocationService","correct":"import boto3\nfrom typing import TYPE_CHECKING\n\nif TYPE_CHECKING:\n    from mypy_boto3_location.client import LocationServiceClient\n\nclient: LocationServiceClient = boto3.client(\"location\")"}],"quickstart":{"code":"import os\nimport boto3\nfrom typing import TYPE_CHECKING\n\nif TYPE_CHECKING:\n    from mypy_boto3_location.client import LocationServiceClient\n    from mypy_boto3_location.type_defs import ListGeofencesResponseTypeDef\n\ndef get_location_client() -> LocationServiceClient:\n    \"\"\"Initializes and returns a typed LocationService client.\"\"\"\n    # AWS credentials will be picked up from environment variables (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)\n    # or ~/.aws/credentials. REGION_NAME is important for LocationService.\n    region = os.environ.get('AWS_REGION', 'us-east-1')\n    return boto3.client('location', region_name=region)\n\ndef list_all_geofences():\n    \"\"\"Lists all geofences using the LocationService client.\"\"\"\n    client = get_location_client()\n    try:\n        response: ListGeofencesResponseTypeDef = client.list_geofences(CollectionName='my-geofence-collection')\n        print(f\"Geofences found: {len(response['Entries'])}\")\n        for entry in response['Entries']:\n            print(f\" - Geofence ID: {entry['GeofenceId']}\")\n    except client.exceptions.ResourceNotFoundException:\n        print(\"Geofence collection 'my-geofence-collection' not found or empty.\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\nif __name__ == '__main__':\n    # This quickstart requires an existing LocationService geofence collection.\n    # Replace 'my-geofence-collection' with an actual collection name in your AWS account.\n    list_all_geofences()","lang":"python","description":"This example demonstrates how to initialize a type-hinted LocationService client and use it to list geofences. It includes an explicit type annotation for the client and the response type, enabling full static analysis and autocomplete."},"warnings":[{"fix":"Upgrade Python to 3.9 or newer.","message":"Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 or older should upgrade their Python version.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.12.0"},{"fix":"Review and update explicit TypeDef imports and references according to the new naming conventions.","message":"TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. Some TypeDefs for packed method arguments use shorter names, and conflicting `Extra` postfixes were moved. This could break code explicitly importing or referencing these TypeDefs.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.9.0"},{"fix":"Install `boto3-stubs-lite[location]` instead of `mypy-boto3-location` or `boto3-stubs[location]`, or configure PyCharm to use an external type checker.","message":"PyCharm users might experience slow performance or high CPU usage due to `Literal` overloads. It is recommended to use `boto3-stubs-lite` or disable PyCharm's internal type checker and rely on `mypy` or `pyright` instead.","severity":"gotcha","affected_versions":"All versions with PyCharm < 2023.2"},{"fix":"Wrap type imports with `if TYPE_CHECKING:` and define fallback `object` assignments for runtime, as shown in the example import section.","message":"For Pylint compatibility, if `mypy-boto3-location` is a `TYPE_CHECKING` dependency, Pylint might complain about undefined variables. A common fix is to set types to `object` in non-`TYPE_CHECKING` mode.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}