{"id":3684,"library":"mypy-boto3-resource-explorer-2","title":"Type Annotations for boto3 Resource Explorer 2","description":"mypy-boto3-resource-explorer-2 provides type annotations for the `boto3` AWS SDK's Resource Explorer 2 service. It enhances development experience by enabling static type checking with tools like MyPy, catching potential errors at development time. The library is part of the `mypy-boto3` project, which generates stubs for all `boto3` services, released frequently in sync with `boto3` and `botocore` updates.","status":"active","version":"1.42.30","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","aws","mypy","type-annotations","stubs","resource-explorer-2","static-analysis"],"install":[{"cmd":"pip install mypy-boto3-resource-explorer-2 boto3","lang":"bash","label":"Install with boto3"},{"cmd":"pip install mypy-boto3-resource-explorer-2","lang":"bash","label":"Install stubs only"}],"dependencies":[{"reason":"Runtime dependency for actual AWS SDK functionality; these stubs provide types for boto3 clients and resources.","package":"boto3","optional":false},{"reason":"Core dependency for underlying botocore service definitions, installed automatically with this package.","package":"types-botocore-resource-explorer-2","optional":false}],"imports":[{"symbol":"ResourceExplorer2Client","correct":"from mypy_boto3_resource_explorer_2.client import ResourceExplorer2Client"},{"symbol":"ResourceExplorer2ServiceResource","correct":"from mypy_boto3_resource_explorer_2.service_resource import ResourceExplorer2ServiceResource"},{"symbol":"SearchInputRequestTypeDef","correct":"from mypy_boto3_resource_explorer_2.type_defs import SearchInputRequestTypeDef"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_resource_explorer_2.client import ResourceExplorer2Client\nfrom mypy_boto3_resource_explorer_2.type_defs import SearchInputRequestTypeDef\nimport os\n\n# Ensure boto3 is configured, e.g., via environment variables or ~/.aws/credentials\n# For testing without actual credentials, you might mock boto3 or use a localstack setup.\n\ndef get_explorer_client() -> ResourceExplorer2Client:\n    \"\"\"Gets a type-hinted AWS Resource Explorer 2 client.\"\"\"\n    # boto3.client expects a string for the service name\n    client: ResourceExplorer2Client = boto3.client(\"resource-explorer-2\")\n    return client\n\n\ndef search_resources(client: ResourceExplorer2Client, query: str):\n    \"\"\"Performs a search using the Resource Explorer 2 client.\"\"\"\n    print(f\"Searching for resources with query: '{query}'\")\n    search_params: SearchInputRequestTypeDef = {\n        \"QueryString\": query,\n        \"MaxResults\": 5\n    }\n    response = client.search(**search_params)\n    \n    print(\"Found Resources:\")\n    for resource in response.get(\"Resources\", []):\n        print(f\"  - Name: {resource.get('ResourceArn')}, Type: {resource.get('ResourceType')}\")\n    \n    return response\n\nif __name__ == \"__main__\":\n    # Example usage\n    explorer_client = get_explorer_client()\n    \n    # An example query (replace with a real query for your AWS account)\n    # For a real run, ensure you have resources indexed by Resource Explorer 2.\n    test_query = \"region:us-east-1 and resource.type:ec2:instance\"\n    \n    # This part will fail if AWS credentials are not configured or if Resource Explorer 2\n    # is not set up in your AWS account/region.\n    # For local testing, consider using localstack with boto3's endpoint_url.\n    try:\n        search_result = search_resources(explorer_client, test_query)\n        print(f\"Search result has a NextToken: {search_result.get('NextToken') is not None}\")\n    except Exception as e:\n        print(f\"Error during search (this might be expected if AWS config/resources are not set up): {e}\")\n\n","lang":"python","description":"This quickstart demonstrates how to obtain a type-hinted `ResourceExplorer2Client` using `boto3` and perform a search operation. It highlights the benefits of `mypy-boto3` by showing how type annotations guide parameter input and response parsing, improving code readability and maintainability."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher.","message":"Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Packages generated with this builder version (including `mypy-boto3-resource-explorer-2` 1.42.30) no longer support Python 3.8.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.12.0, mypy-boto3-resource-explorer-2 >=1.42.30"},{"fix":"Review and update `TypeDef` names in your code to match the new, shorter conventions. Check the generated `type_defs.pyi` for the exact names.","message":"Certain `TypeDef` names for method arguments were shortened or restructured in `mypy-boto3-builder` version 8.9.0. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.9.0, mypy-boto3-resource-explorer-2 >=1.34.0 (approximate)"},{"fix":"Ensure `boto3` is installed in your environment: `pip install boto3`.","message":"Installing `mypy-boto3-resource-explorer-2` only provides type annotations for static analysis tools like MyPy. It does NOT install `boto3` itself. You must install `boto3` separately to run your code.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use the official `boto3` service names as strings when calling `boto3.client()` or `boto3.resource()`.","message":"When obtaining a client from `boto3.client()`, you must pass the correct service name as a string (e.g., `'resource-explorer-2'`). The type hints are applied *after* the client is created, not by modifying how `boto3.client()` works.","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"}