Thyme
Reference

Decorators Reference

Complete reference for all Thyme Python decorators.

@dataset

Registers a class as a dataset with schema metadata. Transforms the class into a dataclass.

from thyme.dataset import dataset, field

@dataset(index=True, version=1)
class MyDataset:
    key_field: str      = field(key=True)
    ts:        datetime = field(timestamp=True)
    value:     float

Parameters

ParameterTypeDefaultDescription
indexboolFalseMaintain a keyed lookup index in the state store
versionint1Schema version for migration tracking

Constraints

  • Exactly one field must be marked field(key=True).
  • Exactly one field must be marked field(timestamp=True).
  • The key field cannot be Optional.

field()

Declares metadata for a dataset field. Used as the default value in a dataset class annotation.

from thyme.dataset import field

user_id: str      = field(key=True)
ts:      datetime = field(timestamp=True)
amount:  float               # plain field — no descriptor needed

Parameters

ParameterTypeDefaultDescription
keyboolFalseMark this field as the entity key
timestampboolFalseMark this field as the event timestamp

@pipeline

Marks a method on a dataset class as a pipeline. Must be combined with @inputs.

from thyme.pipeline import pipeline, inputs

@dataset(index=True)
class OutputDataset:
    ...

    @pipeline(version=1)
    @inputs(InputDataset)
    def my_pipeline(cls, inp: InputDataset):
        return inp.groupby("key").aggregate(...)

Parameters

ParameterTypeDefaultDescription
versionint1Pipeline version for tracking changes

@inputs

Declares the input datasets for a pipeline method.

from thyme.pipeline import inputs

@inputs(DatasetA)                  # single input
@inputs(DatasetA, DatasetB)        # multiple inputs

Parameters

ParameterTypeDescription
*dataset_classesdataset classesOne or more @dataset-decorated classes

@featureset

Registers a class as a featureset. No parameters — use as a bare decorator.

from thyme.featureset import featureset

@featureset
class MyFeatures:
    ...

feature()

Declares a feature in a featureset. Used as the default value in a featureset class annotation.

from thyme.featureset import feature

uid:   str   = feature(id=1)
score: float = feature(id=2)

Parameters

ParameterTypeDescription
idintStable integer identifier. Must be unique within the featureset. Never reuse.

@extractor

Marks a method on a featureset class as an extractor. Can be used with or without arguments.

from thyme.featureset import extractor

# Without arguments
@extractor
def my_extractor(cls, ts, inputs): ...

# With arguments
@extractor(deps=[OtherFeatureset], version=2)
def my_extractor(cls, ts, inputs): ...

Parameters (when called with arguments)

ParameterTypeDefaultDescription
depslist[]Featureset classes this extractor depends on
versionint1Extractor version

Method signature

def extractor_method(cls, ts, inputs):
    # cls: the featureset class
    # ts: query timestamp (datetime)
    # inputs: dict[str, Any] — input feature values
    return output_value_1, output_value_2

@extractor_inputs

Declares the feature names an extractor reads from inputs.

from thyme.featureset import extractor_inputs

@extractor_inputs("uid")
@extractor_inputs("uid", "age")   # multiple

Parameters

ParameterTypeDescription
*feature_namesstrNames of features available in inputs dict

@extractor_outputs

Declares the feature names an extractor returns. Must match the return value order.

from thyme.featureset import extractor_outputs

@extractor_outputs("score")
@extractor_outputs("avg_spend_7d", "txn_count_30d")  # multiple — return tuple

Parameters

ParameterTypeDescription
*feature_namesstrNames of features produced, in return-value order

@source

Attaches a source connector to a dataset class. Must be the outermost decorator.

from thyme.connectors import IcebergSource, source

@source(
    IcebergSource(catalog="prod", database="events", table="transactions"),
    cursor="ts",
    every="1m",
    disorder="5m",
    cdc="append",
)
@dataset(index=True)
class MyDataset: ...

Parameters

ParameterTypeDefaultDescription
connectorconnector objectrequiredThe source connector instance
cursorstr""Incremental cursor field name
everystr""Poll interval ("1m", "5m", "1h")
disorderstr""Late-arrival tolerance ("5m", "1h", "1d")
cdcstr"append"CDC mode: "append", "upsert", or "debezium"

On this page