Type Annotations for boto3 ServiceDiscovery

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-servicediscovery` to obtain a type-hinted ServiceDiscovery client from `boto3.client`. It then calls `list_namespaces` and leverages the provided type definitions for the response, enhancing code completion and static analysis.

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}")

view raw JSON →