Type Annotations for boto3 ServiceDiscovery
mypy-boto3-servicediscovery provides high-quality type annotations for the `boto3` ServiceDiscovery client, paginators, and type definitions. It is part of the `boto3-stubs` project, generated by `mypy-boto3-builder 8.12.0`, and is currently at version 1.42.3. The project maintains an active release cadence, frequently updating to match new `boto3` versions and incorporate fixes.
Warnings
- breaking Support for Python 3.8 has been officially removed starting with `mypy-boto3-builder 8.12.0` (which generated this package version). Users on Python 3.8 will encounter compatibility issues.
- breaking Type definition (TypeDef) naming conventions were changed in `mypy-boto3-builder 8.9.0`. Shorter names are now preferred, and 'Extra' postfixes are moved. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`. If your code explicitly references these generated TypeDefs, it will break.
- breaking The entire `mypy-boto3-builder` ecosystem migrated to PEP 561 compliant packages in `8.12.0`. While this improves type checker discovery, it might affect custom build or package management setups that relied on older distribution methods.
- gotcha For Pylint compatibility when using the `TYPE_CHECKING` flag to conditionally import types, Pylint might complain about undefined variables. A common workaround is to set types to `object` in the `else` branch.
- gotcha Although `boto3-stubs` offers implicit type discovery, explicit type annotations for `boto3.client(...)` and `session.client(...)` calls (e.g., `client: ServiceDiscoveryClient = session.client("servicediscovery")`) are highly recommended for optimal IDE auto-completion and robust static analysis.
Install
-
pip install mypy-boto3-servicediscovery -
pip install 'boto3-stubs[servicediscovery]'
Imports
- ServiceDiscoveryClient
from mypy_boto3_servicediscovery import ServiceDiscoveryClient
- ListNamespacesPaginator
from mypy_boto3_servicediscovery.paginator import ListNamespacesPaginator
- TagTypeDef
from mypy_boto3_servicediscovery.type_defs import TagTypeDef
Quickstart
import boto3
from mypy_boto3_servicediscovery import ServiceDiscoveryClient
from mypy_boto3_servicediscovery.type_defs import ListNamespacesResponseTypeDef
def get_servicediscovery_namespaces() -> list[str]:
# Explicit type annotation for better IDE support and type checking
client: ServiceDiscoveryClient = boto3.client("servicediscovery")
# The response object is also type-hinted
response: ListNamespacesResponseTypeDef = client.list_namespaces()
namespace_names = [ns['Name'] for ns in response.get('Namespaces', []) if 'Name' in ns]
return namespace_names
if __name__ == "__main__":
# This code requires AWS credentials to be configured (e.g., via AWS CLI, env vars)
# If no namespaces exist, it will return an empty list.
try:
namespaces = get_servicediscovery_namespaces()
print(f"ServiceDiscovery Namespaces: {namespaces}")
except Exception as e:
print(f"An error occurred: {e}")