{"id":3013,"library":"mypy-boto3-apigatewayv2","title":"mypy-boto3-apigatewayv2 type annotations","description":"mypy-boto3-apigatewayv2 provides a complete set of type annotations for the boto3 ApiGatewayV2 client and associated data structures, enabling static type checking with tools like MyPy. It ensures type safety and autocompletion for AWS SDK usage. The current version is 1.42.76, aligning with the `boto3` version it targets. New versions are released frequently in sync with `mypy-boto3-builder` updates and AWS API changes.","status":"active","version":"1.42.76","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","mypy","aws","typing","stubs","apigatewayv2","type-checking"],"install":[{"cmd":"pip install boto3 mypy-boto3-apigatewayv2 mypy","lang":"bash","label":"Install Boto3, stubs, and MyPy"}],"dependencies":[{"reason":"This package provides type stubs for boto3, which must be installed separately for runtime functionality.","package":"boto3"},{"reason":"MyPy is the primary static type checker designed to utilize these annotations.","package":"mypy"},{"reason":"May be required by generated stub packages for older Python versions (<3.9), though typically managed automatically.","package":"typing-extensions","optional":true}],"imports":[{"symbol":"ApiGatewayV2Client","correct":"from mypy_boto3_apigatewayv2.client import ApiGatewayV2Client"},{"symbol":"CreateApiRequestRequestTypeDef","correct":"from mypy_boto3_apigatewayv2.type_defs import CreateApiRequestRequestTypeDef"},{"note":"Importing the top-level package helps MyPy discover the stubs implicitly.","symbol":"mypy_boto3_apigatewayv2","correct":"import mypy_boto3_apigatewayv2"}],"quickstart":{"code":"import boto3\nimport mypy_boto3_apigatewayv2  # Import for MyPy to discover stubs\nfrom mypy_boto3_apigatewayv2.client import ApiGatewayV2Client\nfrom mypy_boto3_apigatewayv2.type_defs import CreateApiRequestRequestTypeDef\n\n# Instantiate a boto3 client at runtime. The stub package provides type annotations.\nclient: ApiGatewayV2Client = boto3.client(\"apigatewayv2\")\n\nprint(f\"Client type at runtime: {type(client)}\")\n\n# Example of a type-checked input dictionary for a method call\n# MyPy will validate that 'create_api_params' conforms to CreateApiRequestRequestTypeDef\ncreate_api_params: CreateApiRequestRequestTypeDef = {\n    \"Name\": \"MyExampleApiForTypes\",\n    \"ProtocolType\": \"WEBSOCKET\", # or 'HTTP'\n    \"Description\": \"API created for type demonstration\",\n    \"Tags\": {\"Project\": \"ChecklistDay\"}\n    # Add other required parameters as per AWS API Gateway V2 documentation if performing a real call\n}\n\n# Although this call will likely fail without valid AWS credentials and full required parameters,\n# it is syntactically correct and demonstrates where type-checking benefits apply.\ntry:\n    response = client.create_api(**create_api_params)\n    print(f\"Attempted to create API with ID: {response.get('ApiId', 'N/A')}\")\nexcept Exception as e:\n    print(f\"Note: API call failed, likely due to missing AWS credentials or incomplete parameters. Error: {e}\")\n\n# MyPy would ensure that 'response' is treated as a CreateApiResultTypeDef.","lang":"python","description":"This quickstart demonstrates how to use `mypy-boto3-apigatewayv2` to add type annotations to a `boto3` client. It shows both explicit type hinting for the client and for a request dictionary, which MyPy uses to provide autocompletion and detect type mismatches. Note that `boto3` must be installed alongside the stub package."},"warnings":[{"fix":"Ensure your project uses Python 3.9 or newer. For older Python versions, pin an older `mypy-boto3-builder` version or downgrade the specific stub packages if compatible versions exist.","message":"Python 3.8 support was removed from `mypy-boto3-builder` starting with version 8.12.0. Consequently, stub packages generated by this builder version (and newer) require Python 3.9 or higher.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.12.0 (and generated stubs including mypy-boto3-apigatewayv2)"},{"fix":"Review and update explicit TypeDef imports and usage in your codebase, especially for complex request/response types. Consult the generated stub files for the exact new names.","message":"TypeDef naming conventions changed in `mypy-boto3-builder` 8.9.0, potentially affecting custom TypeDef names. For instance, `CreateDistributionRequestRequestTypeDef` might become `CreateDistributionRequestTypeDef`.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.9.0 (and generated stubs)"},{"fix":"Always include `pip install boto3` alongside `pip install mypy-boto3-apigatewayv2` in your project setup.","message":"The `mypy-boto3-apigatewayv2` package provides only type stubs, not the actual runtime implementation of the AWS SDK. `boto3` must be installed separately for your application to function.","severity":"gotcha","affected_versions":"All"},{"fix":"Always create AWS service clients using `boto3.client('service_name')` or `boto3.resource('service_name')`. Use the imported types from `mypy_boto3_apigatewayv2` solely for type annotations.","message":"Type stubs are not meant for direct instantiation. For example, do not attempt to call `mypy_boto3_apigatewayv2.client.ApiGatewayV2Client()` directly. Instead, use `boto3.client('apigatewayv2')` and let MyPy infer or be guided by the imported types.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}