Type annotations for boto3 AppConfigData
mypy-boto3-appconfigdata provides a standalone package of type annotations for the boto3 AppConfigData service client. It enhances development with static type checking by tools like mypy and provides improved IDE autocompletion for `boto3.client("appconfigdata")`. The current version is 1.42.3, with releases typically synchronized with boto3 versions and updates from the mypy-boto3-builder.
Warnings
- breaking Version 8.12.0 of the underlying `mypy-boto3-builder` (which generates this stub package) removed support for Python 3.8. Users on Python 3.8 must upgrade their Python version.
- breaking With `mypy-boto3-builder` version 8.9.0, some TypeDef naming conventions changed (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). While specific to other services, similar changes may occur in AppConfigData type definitions in future updates, requiring code adjustments.
- gotcha Pylint may complain about undefined variables when using `TYPE_CHECKING` guards to conditionally import stubs. This happens if the `else` branch does not define the types (e.g., `Client = object`).
- gotcha PyCharm users might experience slow performance with `Literal` overloads in `boto3-stubs`. This is a known issue (PY-40997) within PyCharm itself.
Install
-
pip install mypy-boto3-appconfigdata -
pip install 'boto3-stubs[appconfigdata]'
Imports
- AppConfigDataClient
from mypy_boto3_appconfigdata import AppConfigDataClient
- GetLatestConfigurationRequestTypeDef
from mypy_boto3_appconfigdata.type_defs import GetLatestConfigurationRequestTypeDef
Quickstart
import boto3
from mypy_boto3_appconfigdata import AppConfigDataClient
from mypy_boto3_appconfigdata.type_defs import GetLatestConfigurationRequestTypeDef
import os
def get_configuration_data(application: str, environment: str, configuration: str, client_id: str) -> dict:
session = boto3.Session(
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
client: AppConfigDataClient = session.client("appconfigdata")
# First, start a session to get a configuration token
start_session_params = {
"ApplicationIdentifier": application,
"ConfigurationIdentifier": configuration,
"ClientConfigurationVersion": "1.0" # Example version, replace as needed
}
start_session_response = client.start_configuration_session(**start_session_params)
configuration_token = start_session_response["InitialConfigurationToken"]
# Then, get the latest configuration using the token
get_config_params: GetLatestConfigurationRequestTypeDef = {
"ConfigurationToken": configuration_token
}
response = client.get_latest_configuration(**get_config_params)
# The configuration is returned as a streaming body
if 'Configuration' in response and response['Configuration']:
config_data = response['Configuration'].read().decode('utf-8')
print(f"Received configuration: {config_data}")
return {"data": config_data, "content_type": response.get('ContentType')}
return {}
# Example usage (will use dummy credentials if env vars are not set)
if __name__ == "__main__":
# These values would typically come from your AppConfig setup
app_id = "MyApplication"
env_id = "MyEnvironment"
config_id = "MyConfigurationProfile"
client_id = "my-unique-client"
print("Attempting to get AppConfig data...")
config = get_configuration_data(app_id, env_id, config_id, client_id)
if config:
print("Successfully retrieved configuration.")
else:
print("Failed to retrieve configuration or no configuration found.")