Skip to content

Getting started with Kili Events

Kili Character

What is Kili?

Kili is a platform that empowers a data-centric approach to Machine Learning through quality training data creation. It provides collaborative data annotation tools and APIs that enable quick iterations between reliable dataset building and model training. More info about the product here.

If you are looking for the Kili product documentation, it is located here.

Kili Events

Kili system raise multiple events corresponding to user actions.

Each event is described once as a JSON Schema. Events travel over the wire in camelCase (the GraphQL representation, e.g. stepGroupId), and a generated Pydantic v2 package — kili-events — lets you consume them in Python.

Installation

pip install kili-events

camelCase on the wire, snake_case in Python

Events travel over the wire in camelCase (e.g. stepGroupId) — this is the GraphQL shape you receive from the event bus.

The Python package exposes idiomatic snake_case attributes (step_group_id). The Pydantic models map between the two automatically, so you read the wire payload directly and access fields the Pythonic way — but serializing back to the wire requires by_alias=True.

Wire / GraphQL Python attribute
Field name stepGroupId step_group_id
Parse — Event.model_validate(raw)
Serialize to wire — evt.model_dump(by_alias=True)

Parsing an event

from kili_events import ProjectWorkflowStepGroupUpdatedEvent

# `raw` is the camelCase payload received from the event bus
evt = ProjectWorkflowStepGroupUpdatedEvent.model_validate(raw)

# Access fields in snake_case
evt.payload.step_group_id
evt.payload.step_group_name

# Serialize back to the wire format (camelCase) — by_alias is required
evt.model_dump(by_alias=True)
# JSON string variant:
evt.model_dump_json(by_alias=True)

Both input formats work in Python

Thanks to populate_by_name, the Pydantic models accept either the camelCase wire keys or the snake_case field names — for parsing and keyword construction alike. The nested payload models live in each event's module:

from kili_events.ProjectWorkflowStepGroupUpdatedEvent import Payload

Payload(step_group_id="sg1", step_group_name="Review", fields=["status"])   # snake_case
Payload(stepGroupId="sg1", stepGroupName="Review", fields=["status"])       # camelCase

Each event page in the Reference section documents its full schema, with the property names shown in both Python (snake_case) and GraphQL (camelCase) tabs.

Listening to events

When you receive an event without knowing its type in advance, let its subject pick the model:

from kili_events import AssetSkippedEvent, UnknownEventError, parse_event

try:
    evt = parse_event(raw)  # the model of raw["event"], validated
except UnknownEventError:
    ...  # an event added to Kili after this version of kili-events: upgrade it

if isinstance(evt, AssetSkippedEvent):
    evt.payload.asset_id

EVENT_MODELS maps every subject to its model, and get_event_model("asset.skipped") returns one.

Families of events

Each folder of events has a union: AssetWorkflowEvent is every asset.workflow.… event, AssetEvent every asset.… event, and AnyEvent every event. Type a handler with one to receive any event of that family.

FAMILY_PATTERNS gives the pattern of each family's folder (below), which matches exactly its events — and the events a later version adds to the folder:

from kili_events import FAMILY_PATTERNS

FAMILY_PATTERNS["AssetWorkflowEvent"]  # 'asset.workflow.*'

Patterns

A pattern selects events by subject — the format of a plugin's or webhook's event matcher. It is dot-separated names, where * stands for one or more names:

Pattern Matches Does not match
asset.skipped asset.skipped asset.unskipped
asset.* asset.created, asset.workflow.assigned asset, assetStorage.connection.created
asset.workflow.* asset.workflow.lock.created asset.created
asset.*.started asset.analytics.labelMetric.consensus.started asset.started

A pattern starts with a name. asset.workflow.* is FAMILY_PATTERNS["AssetWorkflowEvent"]: it selects the events of that family.

from kili_events import events_matching, matches_subject

matches_subject("asset.workflow.*", "asset.workflow.assigned")  # True
events_matching("asset.issue.*")   # ('asset.issue.cancelled', 'asset.issue.created', 'asset.issue.resolved')
events_matching("label.wokflow.*")  # () — a typo: this pattern would never fire

The TypeScript package exports the same helpers, in camelCase: parseEvent, UnknownEventError, matchesSubject, eventsMatching.