Type Annotations for boto3 DRS
mypy-boto3-drs provides comprehensive type annotations for the AWS Disaster Recovery Service (DRS) client within the boto3 library. Version 1.42.86 is currently available, generated by mypy-boto3-builder 8.12.0. The project maintains an active release cadence, frequently updating stubs to align with new boto3 and botocore versions, ensuring compatibility with popular type checkers like mypy and pyright, as well as IDEs like VSCode and PyCharm.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-drs 1.42.86`), support for Python 3.8 has been removed across all `mypy-boto3` packages.
- breaking The `mypy-boto3-builder` (version 8.9.0 and later, which includes 8.12.0 that generated this stub) introduced breaking changes to `TypeDef` naming conventions. Specifically, 'TypeDefs for packed method arguments use shorter names if possible' and 'Conflicting TypeDef Extra postfix moved to the end'.
- gotcha PyCharm users might experience slow performance and high CPU usage due to `Literal` overloads when using `boto3-stubs`. It is recommended to use `boto3-stubs-lite` (if explicit type annotations are acceptable) or disable PyCharm's internal type checker and rely on `mypy` or `pyright`.
- gotcha When using `TYPE_CHECKING` for conditional imports with Pylint, it might report 'undefined variable' errors for the aliased types in the runtime block. This is a known Pylint issue.
Install
-
pip install mypy-boto3-drs -
pip install 'boto3-stubs[drs]' --extra-index-url https://pypi.org/simple/
Imports
- DRSClient
from mypy_boto3_drs import DRSClient
- DescribeRecoveryInstancesResponseTypeDef
from mypy_boto3_drs.type_defs import DescribeRecoveryInstancesResponseTypeDef
- DRSPaginator
from mypy_boto3_drs.paginator import DescribeRecoveryInstancesPaginator
Quickstart
from typing import TYPE_CHECKING
import boto3
import os
if TYPE_CHECKING:
from mypy_boto3_drs import DRSClient
from mypy_boto3_drs.type_defs import DescribeRecoveryInstancesResponseTypeDef
# Configure AWS credentials and region, e.g., via environment variables or ~/.aws/credentials
# For quickstart, ensure default session is configured or pass explicit creds/region.
def get_drs_recovery_instances() -> None:
# Explicitly type the client for mypy/IDE support
client: DRSClient = boto3.client("drs", region_name=os.environ.get("AWS_REGION", "us-east-1"))
try:
# Example: Describe recovery instances
response: DescribeRecoveryInstancesResponseTypeDef = client.describe_recovery_instances()
print(f"Found {len(response['items'])} DRS Recovery Instances:")
for instance in response['items']:
print(f" - Instance ID: {instance.get('recoveryInstanceID')}, Status: {instance.get('lifeCycle', {}).get('status')}")
except Exception as e:
print(f"Error describing DRS recovery instances: {e}")
if __name__ == "__main__":
# Set dummy values for AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION if not configured
os.environ.setdefault('AWS_ACCESS_KEY_ID', 'testing')
os.environ.setdefault('AWS_SECRET_ACCESS_KEY', 'testing')
os.environ.setdefault('AWS_REGION', 'us-east-1')
get_drs_recovery_instances()