mypy-boto3-support-app Type Stubs
mypy-boto3-support-app provides comprehensive type annotations for the AWS boto3 SupportApp service, enabling static type checking with tools like mypy and enhancing IDE auto-completion. It is part of the larger `mypy-boto3` project, with its current version 1.42.3 being generated by `mypy-boto3-builder 8.12.0`. The library follows a rapid release cadence, aligning with `boto3` updates and `mypy-boto3-builder` enhancements.
Warnings
- breaking As of `mypy-boto3-builder 8.12.0`, Python 3.8 is no longer supported. Projects must use Python 3.9 or higher.
- breaking Version `8.9.0` of `mypy-boto3-builder` introduced breaking changes to `TypeDef` naming conventions. Argument `TypeDefs` now use shorter names, and conflicting `TypeDef` `Extra` postfixes are moved to the end. This can break existing explicit type annotations in your code.
- gotcha Always wrap `mypy-boto3` type imports within an `if TYPE_CHECKING:` block. This prevents the type stub packages from becoming runtime dependencies, keeping your production environment cleaner and lighter.
- gotcha When using PyCharm, performance issues with `Literal` overloads (`PY-40997`) can occur. It is recommended to use the `boto3-stubs-lite` version if you experience slow performance or high CPU usage.
- gotcha For optimal type inference and auto-completion, especially in IDEs that might not fully support function overloads (e.g., older VSCode Python extensions), explicitly annotate `boto3.client()` and `boto3.session.client()` calls with the specific client type (e.g., `client: SupportAppClient = boto3.client("support-app")`).
- gotcha Be aware that AWS service names can change or be deprecated. For example, `sms-voice` was replaced by `pinpoint-sms-voice`. While not specific to 'support-app', this indicates a pattern where service stub packages might be retired or renamed, requiring updates to your dependencies.
Install
-
pip install mypy-boto3-support-app -
pip install 'boto3-stubs[support-app]'
Imports
- SupportAppClient
from mypy_boto3_support_app.client import SupportAppClient
- CreateCaseRequestRequestTypeDef
from mypy_boto3_support_app.type_defs import CreateCaseRequestRequestTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
import os
if TYPE_CHECKING:
from mypy_boto3_support_app.client import SupportAppClient
from mypy_boto3_support_app.type_defs import CreateCaseRequestRequestTypeDef
def create_support_case(
subject: str,
communication_body: str,
service_code: str,
category_code: str
) -> dict:
client: SupportAppClient = boto3.client(
"support-app",
region_name=os.environ.get('AWS_REGION', 'us-east-1'),
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', '')
)
# Example: Defining a request payload with type hints
# Note: Replace with actual required parameters for CreateCase API
request_payload: CreateCaseRequestRequestTypeDef = {
'subject': subject,
'communicationBody': communication_body,
'serviceCode': service_code,
'categoryCode': category_code,
'severityCode': 'low',
'language': 'en'
}
try:
response = client.create_case(**request_payload)
print(f"Successfully created case: {response.get('caseId')}")
return response
except Exception as e:
print(f"Error creating case: {e}")
raise
# Example usage (ensure AWS credentials and region are set in environment variables)
# if __name__ == "__main__":
# # These values are placeholders and would need to be valid for your AWS account
# # For actual usage, retrieve service and category codes from AWS Support documentation
# sample_subject = "My application is experiencing an issue."
# sample_body = "Detailed description of the problem and steps to reproduce."
# sample_service_code = "amazon-ec2" # Example, replace with actual support service code
# sample_category_code = "instance-connect" # Example, replace with actual support category code
#
# # Uncomment to run the example
# # create_support_case(sample_subject, sample_body, sample_service_code, sample_category_code)