Building blocks¶
Extension API. Use these types to define component data, processors, and processor resources.
Component
¶
Base class for typed entity data.
Define a component by subclassing Component and declaring Pydantic fields.
Keep components small and focused on one concern.
Examples:
get_type_by_name
classmethod
¶
Find a Component subclass (at any depth) by its class name.
Raises:
| Type | Description |
|---|---|
ValueError
|
If no matching subclass exists or more than one subclass has the requested name. |
from_dict
classmethod
¶
Create a component instance from a dictionary.
Call this method on a concrete subclass, or include a "type" key
naming a registered subclass when calling Component.from_dict().
Raises:
| Type | Description |
|---|---|
ValueError
|
If the concrete component type cannot be determined. |
to_payload
¶
Serialize this component for command and API payloads.
Unlike model_dump(), the result includes the concrete component
type so Component.from_dict() can reconstruct it.
to_pyarrow_schema
classmethod
¶
Return the unprefixed PyArrow schema for this component type.
get_prefixed_schema
classmethod
¶
Return a PyArrow schema whose fields use the component prefix.
AsyncProcessor
¶
Base class for asynchronous dataframe processors.
Subclasses declare the component types they require and implement
process(). Lower priority values run first. Processors return a new Daft
DataFrame rather than mutating their input.
Examples:
>>> from daft import col
>>> class Health(Component):
... value: int = 100
>>> class Decay(AsyncProcessor):
... components = (Health,)
... priority = 10
...
... async def process(self, df, **kwargs):
... return df.with_column(
... "health__value", col("health__value") - 1
... )
process
async
¶
Transform one archetype dataframe for a simulation tick.
Override this method in subclasses and return a new dataframe.
Resources
¶
Type-safe container for world-level shared state.
Usage
world.resources.insert(SimConfig(gravity=9.8)) world.resources.insert(broker)
In processor¶
config = resources.require(SimConfig) broker = resources.get(CommandBroker) # Returns None if not present
insert_as
¶
Insert a resource keyed by an explicit type rather than type(resource).
Useful in tests when a subclass should be looked up as its base type::
world.resources.insert_as(FakeSpec(client), PolicyClientSpec)
Production processors that call resources.require(PolicyClientSpec)
will then find FakeSpec(client) transparently.