mypy-boto3-events
mypy-boto3-events provides type annotations for the `boto3` AWS EventBridge service client. It enhances code completion and static type checking for `boto3` interactions, ensuring better code quality and developer experience. This library is part of the `mypy-boto3-builder` project, which frequently updates to match `boto3` and `aioboto3` changes. The current version is 1.42.3.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and subsequently across all generated `mypy-boto3-*` packages. Python 3.9 or higher is now required.
- breaking The project migrated to PEP 561 compliant packages in `mypy-boto3-builder` version 8.12.0. This change affects how type stubs are discovered and might require adjustments in some build systems or explicit `mypy` configurations.
- breaking TypeDef names for packed method arguments were shortened (e.g., `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`) in `mypy-boto3-builder` version 8.9.0. Conflicting TypeDefs also had their 'Extra' postfix moved to the end.
- gotcha For optimal auto-completion and type inference in some IDEs (e.g., VSCode) and type checkers, explicit type annotations for `boto3.client()`, `boto3.session.client()`, `client.get_waiter()`, and `client.get_paginator()` calls are often recommended, despite the stubs providing implicit discovery.
- gotcha When using Pylint, it may report 'undefined variable' errors for type-hinted imports (e.g., `from mypy_boto3_events.client import EventBridgeClient`).
- gotcha Service names within the `mypy-boto3` ecosystem can change (e.g., `sms-voice` became `pinpoint-sms-voice`). While not directly affecting `events` currently, this indicates a potential for future updates to require changes to import paths for specific services.
Install
-
pip install mypy-boto3-events -
pip install boto3-stubs[events]
Imports
- EventBridgeClient
from mypy_boto3_events.client import EventBridgeClient
- ListRulesPaginator
from mypy_boto3_events.paginator import ListRulesPaginator
- PutRuleRequestRequestTypeDef
from mypy_boto3_events.type_defs import PutRuleRequestRequestTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_events.client import EventBridgeClient
from mypy_boto3_events.type_defs import PutRuleResponseTypeDef, PutRuleRequestRequestTypeDef
def get_eventbridge_client() -> 'EventBridgeClient':
"""Initializes and returns a type-hinted EventBridge client."""
# boto3.client implicitly returns Any, mypy-boto3 provides the type stubs
client: EventBridgeClient = boto3.client('events')
return client
def put_example_rule():
client = get_eventbridge_client()
rule_params: PutRuleRequestRequestTypeDef = {
"Name": "MyTestRule",
"EventPattern": "{\"source\":[\"aws.ec2\"]}",
"State": "ENABLED"
}
response: PutRuleResponseTypeDef = client.put_rule(**rule_params)
print(f"Rule ARN: {response.get('RuleArn')}")
if __name__ == "__main__":
put_example_rule()