{"id":2607,"library":"mypy-boto3-logs","title":"CloudWatchLogs Type Annotations for Boto3","description":"mypy-boto3-logs provides static type annotations for the `boto3` CloudWatchLogs service, enhancing code quality and developer experience. It is generated by the `mypy-boto3-builder` project and is compatible with various type checkers like mypy and pyright, as well as IDEs like VSCode and PyCharm. The current version is 1.42.83, with frequent updates aligning with `boto3` releases and builder improvements.","status":"active","version":"1.42.83","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["type-annotations","boto3","mypy","cloudwatch-logs","aws","stubs","typing"],"install":[{"cmd":"pip install mypy-boto3-logs boto3 mypy","lang":"bash","label":"Install with boto3 and mypy"},{"cmd":"pip install 'boto3-stubs[logs]' mypy","lang":"bash","label":"Install via boto3-stubs extra (recommended)"}],"dependencies":[{"reason":"Provides the AWS SDK for Python that these stubs annotate.","package":"boto3"},{"reason":"The primary static type checker this library is designed for.","package":"mypy","optional":true},{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"note":"Directly importing from boto3 does not provide type hints; the stub package provides the specific client type.","wrong":"from boto3.session import Session; client: Session().client('logs')","symbol":"CloudWatchLogsClient","correct":"from mypy_boto3_logs.client import CloudWatchLogsClient"},{"note":"Use this for service resources, if available for CloudWatchLogs (less common for logs).","symbol":"CloudWatchLogsServiceResource","correct":"from mypy_boto3_logs.service_resource import CloudWatchLogsServiceResource"},{"note":"TypedDicts for request/response bodies are found in type_defs.","symbol":"PutLogEventsRequestRequestTypeDef","correct":"from mypy_boto3_logs.type_defs import PutLogEventsRequestRequestTypeDef"}],"quickstart":{"code":"from typing import TYPE_CHECKING\nimport boto3\n\nif TYPE_CHECKING:\n    from mypy_boto3_logs.client import CloudWatchLogsClient\n    from mypy_boto3_logs.type_defs import PutLogEventsResponseTypeDef\n\n\ndef get_logs_client() -> 'CloudWatchLogsClient':\n    \"\"\"Returns a type-hinted CloudWatchLogs client.\"\"\"\n    session = boto3.Session(\n        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),\n        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),\n        region_name=os.environ.get('AWS_REGION', 'us-east-1')\n    )\n    return session.client('logs')\n\n\ndef put_log_events_example():\n    \"\"\"Example of using the type-hinted CloudWatchLogs client.\"\"\"\n    client = get_logs_client()\n    response: PutLogEventsResponseTypeDef = client.put_log_events(\n        logGroupName='my-log-group',\n        logStreamName='my-log-stream',\n        logEvents=[\n            {'timestamp': 1678886400000, 'message': 'Hello from mypy-boto3-logs!'}\n        ]\n    )\n    print(f\"Sequence Token: {response.get('nextSequenceToken')}\")\n\nif __name__ == '__main__':\n    import os\n    # Set dummy AWS credentials for local testing or ensure they are in env vars\n    # For actual use, configure boto3 credentials securely\n    if not os.environ.get('AWS_ACCESS_KEY_ID'):\n        os.environ['AWS_ACCESS_KEY_ID'] = 'TEST_ACCESS_KEY'\n        os.environ['AWS_SECRET_ACCESS_KEY'] = 'TEST_SECRET_KEY'\n        os.environ['AWS_REGION'] = 'us-east-1'\n\n    put_log_events_example()\n","lang":"python","description":"This quickstart demonstrates how to obtain a type-hinted CloudWatchLogs client and use it with type-safe operations. The `TYPE_CHECKING` block ensures that `mypy-boto3-logs` is only a development dependency. Replace placeholder credentials with actual AWS configuration for real-world usage."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or a newer version.","message":"Python 3.8 support has been removed as of `mypy-boto3-builder` version 8.12.0. All `mypy-boto3-*` packages now require Python 3.9 or newer.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.12.0, mypy-boto3-logs >= 1.42.83"},{"fix":"Refer to the specific service's documentation or use IDE auto-completion to find the updated TypeDef names for requests and responses.","message":"TypeDef naming conventions changed in `mypy-boto3-builder` 8.9.0. Method argument TypeDefs may use shorter names, and conflicting `Extra` postfixes were moved to the end. This may require updating import paths or references to specific TypedDicts.","severity":"breaking","affected_versions":"mypy-boto3-builder >= 8.9.0"},{"fix":"Ensure `mypy-boto3-logs` is installed in the same Python environment used for `mypy` execution. Avoid relying on `MYPYPATH` for these stub packages.","message":"`mypy-boto3-*` packages migrated to PEP 561. While beneficial, this might impact older `mypy` configurations. Stub-only packages, per PEP 561, cannot be found via `MYPYPATH` and must be installed directly in the environment `mypy` inspects.","severity":"gotcha","affected_versions":"mypy-boto3-builder >= 8.12.0"},{"fix":"Install `boto3-stubs-lite[logs]` (`pip install 'boto3-stubs-lite[logs]'`) or disable PyCharm's type checking.","message":"PyCharm users may experience slow performance or high CPU usage due to Literal overloads. The `boto3-stubs-lite` packages are recommended as a workaround, or disable PyCharm's internal type checker and use `mypy` or `pyright` instead.","severity":"gotcha","affected_versions":"All versions with PyCharm"},{"fix":"Implement the following pattern: `if TYPE_CHECKING: from mypy_boto3_logs.client import CloudWatchLogsClient else: CloudWatchLogsClient = object`","message":"When using `TYPE_CHECKING` for conditional imports, Pylint may incorrectly report undefined variables. A workaround is to assign `object` to the type hints in the non-`TYPE_CHECKING` branch.","severity":"gotcha","affected_versions":"All versions with Pylint"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}