{"id":3098,"library":"mypy-boto3-guardduty","title":"mypy-boto3-guardduty Type Annotations","description":"Type annotations for the `boto3` GuardDuty service, generated with `mypy-boto3-builder`. It provides comprehensive type hints for clients, paginators, literals, and type definitions, ensuring compatibility with static type checkers like mypy and enhancing IDE experiences in VSCode, PyCharm, and others. The library is actively maintained and frequently updated to synchronize with `boto3` and `mypy-boto3-builder` releases, currently at version 1.42.84.","status":"active","version":"1.42.84","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","mypy","type-hints","aws","guardduty","static-analysis","types"],"install":[{"cmd":"pip install mypy-boto3-guardduty boto3","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Runtime dependency for AWS SDK functionality. `mypy-boto3-guardduty` provides type stubs for this package.","package":"boto3","optional":false},{"reason":"Required for some type features on older Python versions (<3.9), automatically handled by `mypy-boto3-builder`'s dependency resolution.","package":"typing-extensions","optional":true}],"imports":[{"symbol":"GuardDutyClient","correct":"from mypy_boto3_guardduty.client import GuardDutyClient"},{"note":"Example of importing a generated TypedDict for request/response bodies.","symbol":"AcceptAdministratorInvitationRequestTypeDef","correct":"from mypy_boto3_guardduty.type_defs import AcceptAdministratorInvitationRequestTypeDef"},{"note":"Example of importing a generated Literal for enum-like string values.","symbol":"AdminStatusType","correct":"from mypy_boto3_guardduty.literals import AdminStatusType"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING\nimport os\n\nif TYPE_CHECKING:\n    from mypy_boto3_guardduty.client import GuardDutyClient\n    from mypy_boto3_guardduty.type_defs import ListDetectorsResponseTypeDef\n\ndef get_guardduty_detectors() -> None:\n    # Explicit type annotation for the client for better IDE support\n    client: GuardDutyClient = boto3.client(\n        \"guardduty\",\n        region_name=os.environ.get('AWS_REGION', 'us-east-1'),\n        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),\n        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET')\n    )\n\n    print(\"Listing GuardDuty detectors...\")\n    try:\n        response: ListDetectorsResponseTypeDef = client.list_detectors()\n        detector_ids = response.get('DetectorIds', [])\n        if detector_ids:\n            print(f\"Found {len(detector_ids)} detectors: {', '.join(detector_ids)}\")\n        else:\n            print(\"No GuardDuty detectors found.\")\n    except client.exceptions.ClientError as e:\n        print(f\"Error listing detectors: {e}\")\n\nif __name__ == \"__main__\":\n    get_guardduty_detectors()","lang":"python","description":"This example demonstrates how to initialize a `GuardDutyClient` with type annotations and list existing detectors. The `TYPE_CHECKING` block ensures that type imports are only active during static analysis, avoiding runtime dependencies. Explicit client annotation is shown for improved IDE autocomplete and type validation."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer. If you must use Python 3.8, pin `mypy-boto3-builder` to a version prior to 8.12.0 and corresponding service stubs, but be aware of potential issues and lack of updates.","message":"Direct support for Python 3.8 was removed starting with `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-guardduty` 1.42.84). The library now officially requires Python >=3.9.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.12.0"},{"fix":"Review your type-hinted code and update `TypeDef` import paths and names to match the new, shortened conventions. The full list of changes would be in the `mypy-boto3-builder` changelog.","message":"Prior to `mypy-boto3-builder` 8.9.0, some generated `TypeDef` names were longer (e.g., `CreateDistributionRequestRequestTypeDef`). Version 8.9.0 introduced changes to shorten these names where possible, which can break existing code relying on the old `TypeDef` names.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.9.0"},{"fix":"Declare the client with its specific type, for example: `client: GuardDutyClient = boto3.client('guardduty')`. This provides the best developer experience.","message":"For optimal IDE support (e.g., in VSCode) and accurate autocompletion for `boto3.client` and `session.client` calls, it is recommended to explicitly type-annotate the client object, as some IDEs may not fully support function overloads for dynamic clients.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To suppress Pylint errors in this scenario, assign `object` to the type-hinted variable in the `else` block of the `if TYPE_CHECKING:` statement. Example: `if TYPE_CHECKING: from mypy_boto3_guardduty.client import GuardDutyClient else: GuardDutyClient = object`.","message":"When using `if TYPE_CHECKING:` blocks to conditionally import type stubs, linters like Pylint may report `undefined-variable` errors for the type-hinted objects in the runtime code path. This happens because Pylint doesn't always correctly parse the `TYPE_CHECKING` guard.","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"}