mypy-boto3-gamelift: Type Annotations for AWS GameLift

1.42.82 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted AWS GameLift client and use it to create a game session. It showcases importing the `Client` type and an example `TypeDef` for request parameters, ensuring static type checking for your boto3 interactions.

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.")

view raw JSON →