mypy-boto3-discovery Type Annotations
This package provides type annotations for the AWS boto3 client for the ApplicationDiscoveryService service. It ensures static type checking with tools like MyPy, catching potential errors before runtime. As of version 1.42.3, it is actively maintained and released in sync with `botocore` updates, typically multiple times a month.
Warnings
- breaking Starting with version 8.12.0, support for Python 3.8 has been removed. Projects using this library must upgrade to Python 3.9 or newer.
- breaking Version 8.12.0 migrated all `mypy-boto3-*` packages to PEP 561-compliant distribution. While `pip install` generally works, advanced `mypy` configurations or custom build systems that directly manipulate stub files might require adjustments.
- gotcha This package provides only type stubs. You must install the `boto3` library separately for your application to function at runtime. Type checkers will use these stubs, but `boto3` is the actual dependency for AWS SDK functionality.
- gotcha For the most accurate type checking, it is crucial to keep your `boto3` library version and your `mypy-boto3-*` stub versions in sync. Significant version discrepancies can lead to incorrect type hints or missing attributes as AWS services evolve.
Install
-
pip install mypy-boto3-discovery -
pip install 'boto3-stubs[discovery]'
Imports
- ApplicationDiscoveryServiceClient
from mypy_boto3_discovery.client import ApplicationDiscoveryServiceClient
- DescribeAgentsResponseTypeDef
from mypy_boto3_discovery.type_defs import DescribeAgentsResponseTypeDef
- AgentInfoTypeDef
from mypy_boto3_discovery.type_defs import AgentInfoTypeDef
Quickstart
import boto3
from mypy_boto3_discovery.client import ApplicationDiscoveryServiceClient
from mypy_boto3_discovery.type_defs import DescribeAgentsResponseTypeDef, AgentInfoTypeDef
import os
def list_discovery_agents() -> None:
# Using type hints for the boto3 client
client: ApplicationDiscoveryServiceClient = boto3.client(
"discovery",
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
try:
# The response object is type-hinted
response: DescribeAgentsResponseTypeDef = client.describe_agents()
agents: list[AgentInfoTypeDef] = response.get("agents", [])
if agents:
print("Discovery Agents:")
for agent in agents:
print(f" Agent ID: {agent.get('agentId')}")
print(f" Agent Status: {agent.get('agentStatus')}")
print(f" Host Name: {agent.get('hostName')}")
print(f" Version: {agent.get('version')}")
print(f" IP Address: {agent.get('agentIp')}")
else:
print("No discovery agents found.")
except Exception as e:
print(f"Error describing agents: {e}")
if __name__ == "__main__":
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# and that the IAM user/role has permissions for 'discovery:DescribeAgents'.
list_discovery_agents()