mypy-boto3-qapps: Type Annotations for AWS QApps
mypy-boto3-qapps provides high-quality type annotations for the `boto3` AWS QApps service client, enabling static type checking with tools like MyPy. It is generated using `mypy-boto3-builder` (currently version 8.12.0) and is updated frequently, often in sync with `boto3` and AWS API changes.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0, Python 3.8 is no longer supported for generated type stubs. Projects targeting `mypy-boto3-qapps` (and other `mypy-boto3-*` packages) must use Python 3.9 or newer.
- breaking TypeDef naming conventions were changed in `mypy-boto3-builder` 8.9.0. Some TypeDef names, especially those ending with `RequestRequestTypeDef` or `ExtraRequestTypeDef`, have been shortened or reordered (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). This impacts direct imports of TypeDef classes.
- gotcha The `mypy-boto3-*` packages are service-specific type stubs. You must install the specific package for each AWS service you use (e.g., `mypy-boto3-qapps` for QApps). Installing `mypy-boto3` (the meta-package) includes stubs for all services and can lead to a large installation footprint and potential conflicts.
- gotcha When annotating a `boto3` client with `mypy-boto3` types, it's best practice to wrap the type annotation in a `if TYPE_CHECKING:` block. This prevents runtime `ImportError` if `mypy-boto3-*` stubs are installed as development dependencies and not available in the production environment.
Install
-
pip install mypy-boto3-qapps -
pip install boto3
Imports
- QAppsClient
from mypy_boto3_qapps.client import QAppsClient
- CreateQAppRequestRequestTypeDef
from mypy_boto3_qapps.type_defs import CreateQAppRequestRequestTypeDef
- QAppsServiceResource
from mypy_boto3_qapps.service_resource import QAppsServiceResource
Quickstart
import boto3
from typing import TYPE_CHECKING, Dict, Any
from mypy_boto3_qapps.client import QAppsClient
from mypy_boto3_qapps.type_defs import CreateQAppRequestRequestTypeDef, CreateQAppResponseTypeDef
# Instantiate the boto3 client, annotated with mypy-boto3 types
# Use TYPE_CHECKING block to avoid runtime dependency if stubs are dev-only
if TYPE_CHECKING:
client: QAppsClient = boto3.client("qapps")
else:
client = boto3.client("qapps")
# Example: Create a QApp
# Note: This is a dummy example; replace placeholder values with actual data.
# The instanceId typically refers to an Amazon Q instance.
instance_id = "your_amazon_q_instance_id" # e.g., 'your-instance-id'
create_qapp_params: CreateQAppRequestRequestTypeDef = {
"instanceId": instance_id,
"appDefinition": {
"appDefinitionArn": "arn:aws:qapps:region:account:app/id", # Example ARN
"appDefinitionType": "PACKAGE_JSON"
}
# "tags": {"key": "value"} # Optional
}
try:
print(f"Attempting to create QApp for instance: {instance_id}")
response: CreateQAppResponseTypeDef = client.create_q_app(
**create_qapp_params
)
print(f"Successfully created QApp.")
print(f"App ID: {response.get('appId')}")
print(f"App ARN: {response.get('appArn')}")
print(f"Status: {response.get('status')}")
except client.exceptions.ValidationException as e:
print(f"Validation Error: {e}")
except client.exceptions.ResourceNotFoundException as e:
print(f"Resource Not Found Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")