{"id":3049,"library":"mypy-boto3-cloudtrail","title":"Type Annotations for boto3 CloudTrail","description":"mypy-boto3-cloudtrail provides comprehensive type annotations for the boto3 CloudTrail service, enhancing developer experience with static analysis tools like mypy, pyright, and various IDEs (VSCode, PyCharm). It ensures type-safe interactions with AWS CloudTrail APIs by providing precise type hints for clients, paginators, and service-specific TypedDicts. This package is generated by `mypy-boto3-builder` and is currently at version 1.42.3, following the corresponding boto3 version. New releases are frequent, typically aligning with boto3 updates.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","cloudtrail","mypy","type-hints","stubs","static-analysis"],"install":[{"cmd":"pip install mypy-boto3-cloudtrail","lang":"bash","label":"Standalone package"},{"cmd":"pip install 'boto3-stubs[cloudtrail]'","lang":"bash","label":"Part of boto3-stubs (recommended for multiple services)"}],"dependencies":[{"reason":"Runtime dependency for AWS SDK functionality, `mypy-boto3-cloudtrail` provides type stubs for it.","package":"boto3"},{"reason":"Primary static type checker to leverage these annotations.","package":"mypy","optional":true},{"reason":"Required for some type features on older Python versions, though typically handled automatically by `boto3-stubs`'s `install_requires`.","package":"typing-extensions","optional":true}],"imports":[{"symbol":"CloudTrailClient","correct":"from mypy_boto3_cloudtrail.client import CloudTrailClient"},{"symbol":"LookupEventsPaginator","correct":"from mypy_boto3_cloudtrail.paginator import LookupEventsPaginator"},{"note":"Importing directly from boto3's internal client module does not provide mypy-boto3 type hints. The `CloudTrailClient` from `mypy_boto3_cloudtrail.client` is the correctly typed version to use with boto3.client().","wrong":"from boto3.cloudtrail.client import Client","symbol":"LookupEventsResponseTypeDef","correct":"from mypy_boto3_cloudtrail.type_defs import LookupEventsResponseTypeDef"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING, List, Dict, Any\n\nif TYPE_CHECKING:\n    from mypy_boto3_cloudtrail.client import CloudTrailClient\n    from mypy_boto3_cloudtrail.type_defs import EventTypeDef, LookupEventsResponseTypeDef\n\n\ndef list_cloudtrail_events(client: 'CloudTrailClient') -> List['EventTypeDef']:\n    \"\"\"Lists recent CloudTrail events with type hints.\"\"\"\n    # Example of a typed client call\n    response: 'LookupEventsResponseTypeDef' = client.lookup_events(MaxResults=5)\n    events: List['EventTypeDef'] = response.get('Events', [])\n    for event in events:\n        print(f\"Event Name: {event.get('EventName')}, Event ID: {event.get('EventId')}\")\n    return events\n\n\nif __name__ == \"__main__\":\n    # In a real application, credentials would be configured via environment variables, ~/.aws/credentials, etc.\n    # For this example, we assume default configuration.\n    boto_session = boto3.Session()\n    \n    # The type hint here ensures static analysis tools understand the client's methods and return types\n    cloudtrail_client: 'CloudTrailClient' = boto_session.client('cloudtrail')\n    \n    print(\"Listing CloudTrail events (first 5):\")\n    try:\n        listed_events = list_cloudtrail_events(cloudtrail_client)\n        if not listed_events:\n            print(\"No events found.\")\n    except Exception as e:\n        print(f\"Error listing events: {e}\")","lang":"python","description":"This quickstart demonstrates how to instantiate a boto3 CloudTrail client and use the `mypy-boto3-cloudtrail` type hints for methods and response structures. It includes an example of looking up events and iterating through the typed response. The `TYPE_CHECKING` block ensures that these stub imports are only used by type checkers and not during runtime, making it safe for production."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Support for Python 3.8 and older was removed in `mypy-boto3-builder` version 8.12.0. All generated `mypy-boto3-*` packages, including `mypy-boto3-cloudtrail`, now require Python >= 3.9.","severity":"breaking","affected_versions":">=8.12.0 (builder), >=1.42.0 (stubs)"},{"fix":"Review your `TypeDef` imports and usage after upgrading, as some names might have been shortened or reordered. Consult the `mypy-boto3` documentation for specific services.","message":"In `mypy-boto3-builder` 8.9.0, there were changes to how TypeDef names are generated, specifically for packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and conflicting `Extra` postfixes (`CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`). While `cloudtrail` specific types might not match these exact examples, similar renamings could apply to other service `TypeDef`s.","severity":"breaking","affected_versions":">=8.9.0 (builder)"},{"fix":"Install `boto3-stubs-lite[cloudtrail]` instead of `boto3-stubs[cloudtrail]` or `mypy-boto3-cloudtrail` if performance is an issue in PyCharm, or configure your IDE to use an external type checker.","message":"PyCharm users might experience slow performance with Literal overloads (issue PY-40997). The recommendation is to use `boto3-stubs-lite` (e.g., `pip install 'boto3-stubs-lite[cloudtrail]'`) or disable PyCharm's internal type checker and rely on `mypy` or `pyright`.","severity":"gotcha","affected_versions":"All versions with PyCharm"},{"fix":"Wrap your type-hinted variable declarations with an `if TYPE_CHECKING:` block and assign `object` in the `else` branch, as shown in the quickstart example (e.g., `if TYPE_CHECKING: from mypy_boto3_cloudtrail.client import CloudTrailClient else: CloudTrailClient = object`).","message":"When using `TYPE_CHECKING` blocks for conditional imports to avoid runtime dependencies (common for stub packages), Pylint might complain about undefined variables. To fix this, set variables inside the `TYPE_CHECKING` block to `object` in the `else` branch.","severity":"gotcha","affected_versions":"All versions with Pylint"},{"fix":"Ensure your `pip` and `mypy` versions are up-to-date. If encountering issues with type discovery in complex environments, verify the `py.typed` marker file is correctly recognized by your tooling.","message":"The `mypy-boto3-builder` migrated to PEP 561 compliant packages in version 8.12.0. While designed to be backward compatible for standard usage, this fundamental change in packaging type information might affect highly customized build systems or older `mypy`/`pip` versions that relied on pre-PEP 561 behavior.","severity":"breaking","affected_versions":">=8.12.0 (builder), >=1.42.0 (stubs)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}