mypy-boto3-events

1.42.3 · active · verified Fri Apr 10

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

Install

Imports

Quickstart

This quickstart demonstrates how to get a type-hinted EventBridge client and use a method with its corresponding TypeDefs. The `TYPE_CHECKING` block ensures that `mypy-boto3-events` is only a dev dependency. Note the explicit type annotation for `boto3.client` is often required for full IDE auto-completion.

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()

view raw JSON →