{"id":3077,"library":"mypy-boto3-ds","title":"mypy-boto3-ds: Type Annotations for boto3 DirectoryService","description":"mypy-boto3-ds provides comprehensive type annotations for the `boto3` AWS SDK's DirectoryService client, enabling static type checking with tools like `mypy`. It's part of the larger `mypy-boto3` (now often referred to as `types-boto3`) project, which automatically generates stubs directly from botocore schemas. This ensures robust type-hinting, improved IDE autocompletion, and early error detection for your AWS interactions. The library is actively maintained, with new versions released in lockstep with `boto3` updates, currently at version 1.42.3.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["AWS","Boto3","Type Hints","Mypy","Static Analysis","DirectoryService"],"install":[{"cmd":"pip install mypy-boto3-ds boto3","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Python 3.8 support was removed in mypy-boto3-builder 8.12.0, which generated this version.","package":"python","version":">=3.9"},{"reason":"This package provides type stubs for the boto3 library, which is a runtime dependency.","package":"boto3","version":"~=1.42.3"}],"imports":[{"symbol":"DirectoryServiceClient","correct":"from mypy_boto3_ds.client import DirectoryServiceClient"},{"symbol":"DescribeDirectoriesResponseTypeDef","correct":"from mypy_boto3_ds.type_defs import DescribeDirectoriesResponseTypeDef"},{"symbol":"DirectoryTypeDef","correct":"from mypy_boto3_ds.type_defs import DirectoryTypeDef"},{"note":"boto3.client itself does not expose type-hintable service clients directly. Stubs are imported under a `TYPE_CHECKING` guard.","wrong":"from boto3.client import DirectoryServiceClient","symbol":"Client Type Hinting (general)","correct":"from typing import TYPE_CHECKING\nif TYPE_CHECKING:\n    from mypy_boto3_ds.client import DirectoryServiceClient"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING, List, Dict, Any\n\n# Using TYPE_CHECKING to ensure type imports are only for static analysis\nif TYPE_CHECKING:\n    from mypy_boto3_ds.client import DirectoryServiceClient\n    from mypy_boto3_ds.type_defs import DirectoryTypeDef, DescribeDirectoriesResultTypeDef\n\ndef get_ds_client() -> \"DirectoryServiceClient\":\n    \"\"\"Returns a type-hinted DirectoryService client.\"\"\"\n    return boto3.client(\"ds\")\n\ndef list_all_directories() -> List[\"DirectoryTypeDef\"]:\n    \"\"\"Lists all Directory Service directories with type hints.\"\"\"\n    client: \"DirectoryServiceClient\" = get_ds_client()\n    response: \"DescribeDirectoriesResultTypeDef\" = client.describe_directories()\n    # Accessing 'DirectoryDescriptions' is now type-checked\n    return response.get(\"DirectoryDescriptions\", [])\n\nif __name__ == \"__main__\":\n    print(\"Attempting to list Directory Service directories...\")\n    try:\n        directories = list_all_directories()\n        if directories:\n            print(f\"Found {len(directories)} directories:\")\n            for directory in directories:\n                # Dictionary access is also type-checked with TypedDicts\n                print(f\"- {directory['Name']} ({directory['DirectoryId']}) - {directory['Type']}\")\n        else:\n            print(\"No Directory Service directories found.\")\n    except Exception as e:\n        print(f\"Error listing directories: {e}\")\n        print(\"Ensure you have AWS credentials configured (e.g., via environment variables, ~/.aws/credentials) and sufficient permissions.\")","lang":"python","description":"This quickstart demonstrates how to obtain a type-hinted DirectoryService client and use it to list directories. The `if TYPE_CHECKING` block ensures that the `mypy-boto3-ds` imports are only used by type checkers, preventing them from becoming runtime dependencies. It also shows how to type-hint the client object and the response structure, enabling better autocompletion and static analysis."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher. Adjust your `pyproject.toml` or `setup.py` to reflect the new minimum Python version.","message":"Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0 (corresponding to `mypy-boto3-ds` 1.42.3 generation). Projects using Python 3.8 or older will encounter issues.","severity":"breaking","affected_versions":">=1.42.3"},{"fix":"Review your code for explicit TypeDef imports and adjust names according to the latest `mypy-boto3-ds` documentation or your type checker's suggestions. Consider using an IDE with good type-hinting support.","message":"In `mypy-boto3-builder` 8.9.0, there were breaking changes to TypeDef naming conventions, such as `CreateDistributionRequestRequestTypeDef` becoming `CreateDistributionRequestTypeDef`. While this specific example is not for DirectoryService, similar renames could affect other service TypeDefs.","severity":"breaking","affected_versions":">=1.34.0 (builder 8.9.0 onwards)"},{"fix":"Always use `from typing import TYPE_CHECKING` and enclose `from mypy_boto3_ds...` imports inside `if TYPE_CHECKING:` blocks.","message":"It is crucial to wrap `mypy-boto3-ds` specific imports within an `if TYPE_CHECKING:` block. Without this guard, the stub packages may become unnecessary runtime dependencies, potentially increasing deployment size or causing import errors if not properly installed in the runtime environment.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Import the client type directly from the stub package: `from mypy_boto3_ds.client import DirectoryServiceClient` (preferably under `if TYPE_CHECKING:`).","message":"While `mypy-boto3-ds` provides stubs for `boto3`, directly importing client objects like `from boto3.client import DirectoryServiceClient` will not work for type checking. The actual client objects are dynamically generated by `boto3` at runtime.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For general usage, consider `pip install boto3-stubs[ds]` or `pip install types-boto3-ds`. `mypy-boto3-ds` is the standalone package for DirectoryService stubs.","message":"The `mypy-boto3` project is now often referred to as `types-boto3` for its meta-package that can install stubs for all services. While `mypy-boto3-ds` is a specific service stub, referring to `mypy-boto3` in general discussions might lead to outdated documentation or package names.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}