{"id":3565,"library":"mypy-boto3-cloudtrail-data","title":"mypy-boto3-cloudtrail-data Type Annotations","description":"Provides type annotations for `boto3`'s CloudTrailDataService, generated by `mypy-boto3-builder`. It enhances static type checking and IDE auto-completion for `boto3` users, currently supporting `boto3` version 1.42.3. Releases follow `boto3`'s release cycle to ensure compatibility.","status":"active","version":"1.42.3","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["mypy","boto3","aws","cloudtrail-data","types","type-stubs","static-analysis"],"install":[{"cmd":"pip install mypy-boto3-cloudtrail-data boto3","lang":"bash","label":"Install with boto3"}],"dependencies":[{"reason":"This package provides type stubs for the `boto3` library; `boto3` itself must be installed to run code.","package":"boto3"}],"imports":[{"note":"This is the primary client type for the CloudTrail Data service.","symbol":"CloudTrailDataServiceClient","correct":"from mypy_boto3_cloudtrail_data.client import CloudTrailDataServiceClient"},{"note":"Type definition for the request parameters of `put_audit_events`.","symbol":"PutAuditEventsRequestRequestTypeDef","correct":"from mypy_boto3_cloudtrail_data.type_defs import PutAuditEventsRequestRequestTypeDef"},{"note":"Type definition for the response of `put_audit_events`.","symbol":"PutAuditEventsResponseTypeDef","correct":"from mypy_boto3_cloudtrail_data.type_defs import PutAuditEventsResponseTypeDef"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING, List, Dict, Any\n\nif TYPE_CHECKING:\n    from mypy_boto3_cloudtrail_data.client import CloudTrailDataServiceClient\n    from mypy_boto3_cloudtrail_data.type_defs import (AuditRecordEntryTypeDef, PutAuditEventsRequestRequestTypeDef, PutAuditEventsResponseTypeDef)\n\n\ndef put_cloudtrail_audit_events(event_data_store_id: str, audit_events: List[AuditRecordEntryTypeDef]) -> PutAuditEventsResponseTypeDef:\n    \"\"\"Puts audit events into CloudTrail Lake with type hints.\"\"\"\n    # Boto3 client without type hint - mypy will complain if mypy-boto3 is installed\n    # Use TYPE_CHECKING guard for production code to avoid runtime dependency on mypy-boto3\n    if TYPE_CHECKING:\n        client: CloudTrailDataServiceClient = boto3.client(\"cloudtrail-data\")\n    else:\n        client = boto3.client(\"cloudtrail-data\")\n\n    # Example request payload with type hint\n    request_payload: PutAuditEventsRequestRequestTypeDef = {\n        \"audit_events\": audit_events,\n        \"EventDataStore\": event_data_store_id\n    }\n\n    print(f\"Putting {len(audit_events)} audit events into {event_data_store_id}...\")\n    response: PutAuditEventsResponseTypeDef = client.put_audit_events(**request_payload)\n    print(f\"Result: {response['FailedEntries']}\")\n    return response\n\n\nif __name__ == \"__main__\":\n    # Replace with your actual Event Data Store ID\n    # For a runnable example, ensure AWS credentials are configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)\n    # and an existing CloudTrail Lake Event Data Store ID is provided.\n    sample_event_data_store_id = \"your-event-data-store-id\" # os.environ.get('CLOUD_TRAIL_DATA_STORE_ID', 'your-event-data-store-id')\n\n    sample_audit_events: List[AuditRecordEntryTypeDef] = [\n        {\n            \"EventID\": \"example-event-id-1\",\n            \"EventData\": \"{\\\"eventVersion\\\":\\\"1.08\\\",\\\"userIdentity\\\":{\\\"type\\\":\\\"IAMUser\\\",\\\"principalId\\\":\\\"AIDAJ45Q7YDR2T3W4XXXB\\\",\\\"arn\\\":\\\"arn:aws:iam::123456789012:user/Alice\\\",\\\"accountId\\\":\\\"123456789012\\\",\\\"userName\\\":\\\"Alice\\\"},\\\"eventTime\\\":\\\"2026-04-11T12:00:00Z\\\",\\\"eventSource\\\":\\\"my.application.com\\\",\\\"eventName\\\":\\\"Login\\\",\\\"awsRegion\\\":\\\"us-east-1\\\",\\\"sourceIPAddress\\\":\\\"203.0.113.1\\\",\\\"userAgent\\\":\\\"Mozilla/5.0\\\",\\\"requestParameters\\\":null,\\\"responseElements\\\":null}\",\n            \"EventDataChecksum\": \"string\", # Optional, required if provided for integrity check\n            \"ExternalID\": \"string\" # Optional\n        },\n        {\n            \"EventID\": \"example-event-id-2\",\n            \"EventData\": \"{\\\"eventVersion\\\":\\\"1.08\\\",\\\"userIdentity\\\":{\\\"type\\\":\\\"IAMUser\\\",\\\"principalId\\\":\\\"AIDAJ45Q7YDR2T3W4XXXC\\\",\\\"arn\\\":\\\"arn:aws:iam::123456789012:user/Bob\\\",\\\"accountId\\\":\\\"123456789012\\\",\\\"userName\\\":\\\"Bob\\\"},\\\"eventTime\\\":\\\"2026-04-11T12:01:00Z\\\",\\\"eventSource\\\":\\\"my.application.com\\\",\\\"eventName\\\":\\\"Logout\\\",\\\"awsRegion\\\":\\\"us-east-1\\\",\\\"sourceIPAddress\\\":\\\"203.0.113.2\\\",\\\"userAgent\\\":\\\"Chrome\\\",\\\"requestParameters\\\":null,\\\"responseElements\\\":null}\"\n        }\n    ]\n\n    try:\n        # Ensure to replace 'your-event-data-store-id' with a valid ID from your AWS account\n        if sample_event_data_store_id == 'your-event-data-store-id':\n            print(\"Please replace 'your-event-data-store-id' with a valid CloudTrail Lake Event Data Store ID.\")\n        else:\n            result = put_cloudtrail_audit_events(sample_event_data_store_id, sample_audit_events)\n            if result.get(\"FailedEntries\"):\n                print(f\"Some events failed: {result['FailedEntries']}\")\n            else:\n                print(\"All events successfully put.\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n","lang":"python","description":"This example demonstrates how to use the `mypy-boto3-cloudtrail-data` type annotations with a `boto3` client to put audit events into AWS CloudTrail Lake. It showcases explicit type hints for the client and the request/response payloads, which enable static type checking and improved IDE support."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or later. Ensure your `requires_python` matches your project's `pyproject.toml` or `setup.cfg`.","message":"`mypy-boto3` packages (including this one) removed support for Python 3.8 starting with `mypy-boto3-builder` version 8.12.0. The package now requires Python 3.9 or higher.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.12.0 (all generated stubs)"},{"fix":"Review your `TypeDef` imports and usage for the specific service and adjust names according to the latest generated types. Your IDE with `mypy-boto3` installed should help identify these.","message":"Starting with `mypy-boto3-builder` 8.9.0, some `TypeDef` names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and conflicting `Extra` postfixes moved to the end. This may require updating import paths and type references in your code.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.9.0 (all generated stubs)"},{"fix":"Always install `mypy-boto3-cloudtrail-data` with the same major.minor.patch version as your `boto3` installation (e.g., `boto3==1.42.3` and `mypy-boto3-cloudtrail-data==1.42.3`).","message":"It is crucial to match the `mypy-boto3-*` package version with your installed `boto3` version to ensure accurate type checking and avoid `mypy` errors or incorrect hints.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure both `boto3` and `mypy-boto3-cloudtrail-data` are listed in your project's dependencies.","message":"This package provides *type stubs* only. You must also install the actual `boto3` library for your code to run at runtime.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When initializing a client, add the explicit type hint: `client: CloudTrailDataServiceClient = boto3.client('cloudtrail-data')`.","message":"For optimal IDE auto-completion and static analysis with `mypy`, explicit type annotations for `boto3.client()` calls are often required. While `boto3-stubs` provides some overload magic, explicit types are the most reliable.","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"}