mypy-boto3-gamelift: Type Annotations for AWS GameLift
mypy-boto3-gamelift provides comprehensive type annotations for the boto3 AWS GameLift service. It enhances development experience by enabling static type checking for GameLift client methods and response/request structures. Currently at version 1.42.82, it is generated by the mypy-boto3-builder and generally releases new versions in sync with upstream boto3 and builder updates.
Warnings
- breaking Support for Python 3.8 was removed from `mypy-boto3-builder` (and consequently generated `mypy-boto3` packages including `mypy-boto3-gamelift`) in version 8.12.0.
- gotcha This package provides only type annotations. The actual `boto3` library is a separate runtime dependency and must be installed alongside `mypy-boto3-gamelift` for your code to execute.
- breaking Type Definition (TypeDef) names for request/response bodies were sometimes shortened or had postfixes reordered in `mypy-boto3-builder` version 8.9.0. If you explicitly imported specific `type_defs` in previous versions, these names may have changed.
- gotcha The `mypy-boto3` ecosystem closely tracks AWS service APIs. Specific services may be renamed or removed from generation (e.g., `sms-voice` was removed in builder v8.11.0). Be aware of potential service availability changes when upgrading major `boto3` or `mypy-boto3` versions.
Install
-
pip install mypy-boto3-gamelift boto3
Imports
- GameLiftClient
from mypy_boto3_gamelift import GameLiftClient
- Client
from mypy_boto3_gamelift import Client
- CreateGameSessionInputRequestTypeDef
from mypy_boto3_gamelift.type_defs import CreateGameSessionInputRequestTypeDef
Quickstart
import boto3
from mypy_boto3_gamelift import Client
from typing import TYPE_CHECKING
# Best practice: use TYPE_CHECKING for type imports to avoid runtime import overhead
if TYPE_CHECKING:
from mypy_boto3_gamelift.type_defs import CreateGameSessionInputRequestTypeDef
def create_gamelift_session(alias_id: str, capacity: int, region: str = "us-east-1") -> dict:
client: Client = boto3.client("gamelift", region_name=region)
# Example using a typed request body (if TYPE_CHECKING is True)
request_body: 'CreateGameSessionInputRequestTypeDef' = {
'MaximumPlayerSessionCount': capacity,
'AliasId': alias_id
# 'FleetId': 'YOUR_FLEET_ID' # Add FleetId if not using AliasId
}
try:
response = client.create_game_session(**request_body)
print(f"Game session created: {response['GameSession']['GameSessionId']}")
return response
except client.exceptions.ConflictException as e:
print(f"Error creating game session: {e}")
raise
except Exception as e:
print(f"An unexpected error occurred: {e}")
raise
# Example usage (replace with actual values):
# if __name__ == "__main__":
# try:
# create_gamelift_session(alias_id="alias-xxxxxxx", capacity=10, region="us-west-2")
# except Exception:
# print("Failed to create game session.")