> ## Documentation Index
> Fetch the complete documentation index at: https://developer.kodexa.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Event Handling with Modules

> Build event-handler modules in Kodexa that react to platform events such as uploads, transitions, and document changes alongside training and inference.

In some cases, we want to have modules that not only handle training and inference, but can also react to events from the platform.

An example might be a module that is used to determine which documents should be inferred in a project for example. These are not traditional modules, but are really event handlers that are triggered by events in the platform. To support this, we need to do two things:

* Add a flag to our module metadata to indicate that we want to handle events
* Include a new method that will receive the event

## Setting up a module to handle events

To set up a module to handle events, we need to add a new flag to the module metadata called `eventAware` and set it to `true`.

```yaml theme={null}
slug: my-module
version: 1.0.0
orgSlug: kodexa
type: store
storeType: MODEL
name: My Event Module
metadata:
  eventAware: true
  moduleRuntimeRef: kodexa/base-module-runtime
  type: module

  contents:
    - module/*
```

Then in your module, add a `handle_event` function. Event-aware modules receive the same injected runtime parameters as inference modules, so you typically read the raw event data from `pipeline_context.context`.

```python theme={null}
import logging

logger = logging.getLogger(__name__)


def handle_event(document=None, pipeline_context=None, status_reporter=None):
    context = pipeline_context.context if pipeline_context else {}

    if status_reporter:
        status_reporter.update("Handling event", status_type="processing")

    logger.info(
        "Received event %s for document family %s",
        context.get("eventType"),
        context.get("documentFamilyId"),
    )

    return document
```

If the event is tied to a content object, `document` is hydrated for you. Otherwise, use `pipeline_context.context` for the event metadata you need.
