Python SDK for Feast - an open source feature store for machine learning that manages features for both training and serving environments.
—
Entities define the primary keys and identifiers around which features are organized in Feast. They establish the join keys used to associate features with specific instances and enable proper data relationships across different feature views.
Create entity definitions that specify the join keys, data types, and metadata for feature groupings.
class Entity:
def __init__(
self,
*,
name: str,
join_keys: Optional[List[str]] = None,
value_type: Optional[ValueType] = None,
description: str = "",
tags: Optional[Dict[str, str]] = None,
owner: str = ""
):
"""
Define an entity for feature organization.
Parameters:
- name: Unique entity name
- join_keys: List of properties for joining (defaults to [name] if not specified)
- value_type: Data type of the entity key (inferred if not specified)
- description: Human-readable description
- tags: Key-value metadata tags
- owner: Entity owner/maintainer identifier
"""Access and modify entity attributes for runtime inspection and configuration.
@property
def name(self) -> str:
"""Entity name."""
@property
def value_type(self) -> ValueType:
"""Entity value type."""
@property
def join_keys(self) -> List[str]:
"""Join keys for feature associations."""
@property
def description(self) -> str:
"""Entity description."""
@property
def tags(self) -> Dict[str, str]:
"""Entity tags."""
@property
def owner(self) -> str:
"""Entity owner."""Convert entities to and from protocol buffer format for registry storage and network communication.
def to_proto(self) -> EntityProto:
"""Convert entity to protocol buffer format."""
@classmethod
def from_proto(cls, entity_proto: EntityProto) -> "Entity":
"""Create entity from protocol buffer."""Entity value types specify the data type of entity keys for proper type checking and serialization.
class ValueType(Enum):
"""Supported entity value types."""
UNKNOWN = 0
BYTES = 1
STRING = 2
INT32 = 3
INT64 = 4
DOUBLE = 5
FLOAT = 6
BOOL = 7
UNIX_TIMESTAMP = 8
BYTES_LIST = 11
STRING_LIST = 12
INT32_LIST = 13
INT64_LIST = 14
DOUBLE_LIST = 15
FLOAT_LIST = 16
BOOL_LIST = 17
UNIX_TIMESTAMP_LIST = 18
NULL = 19
PDF_BYTES = 20from feast import Entity, ValueType
# Create a customer entity
customer = Entity(
name="customer",
value_type=ValueType.INT64,
description="Customer identifier",
tags={"team": "marketing", "pii": "false"}
)
# Create a product entity with custom join keys
product = Entity(
name="product",
value_type=ValueType.STRING,
join_keys=["product_id"],
description="Product SKU identifier",
owner="product-team@company.com"
)
# Create a location entity
location = Entity(
name="location",
value_type=ValueType.STRING,
description="Geographic location code"
)from feast import FeatureView, Field, FileSource
from datetime import timedelta
# Use entities in feature view definitions
customer_features = FeatureView(
name="customer_features",
entities=[customer], # Reference the entity
ttl=timedelta(days=1),
schema=[
Field(name="age", dtype=ValueType.INT64),
Field(name="income", dtype=ValueType.DOUBLE),
Field(name="city", dtype=ValueType.STRING)
],
source=FileSource(path="data/customers.parquet", timestamp_field="ts")
)
# Multi-entity feature view
order_features = FeatureView(
name="order_features",
entities=[customer, product], # Multiple entities
ttl=timedelta(hours=24),
schema=[
Field(name="quantity", dtype=ValueType.INT32),
Field(name="price", dtype=ValueType.DOUBLE)
],
source=FileSource(path="data/orders.parquet", timestamp_field="order_time")
)# Inspect entity properties
print(f"Entity name: {customer.name}")
print(f"Value type: {customer.value_type}")
print(f"Join keys: {customer.join_keys}")
print(f"Description: {customer.description}")
print(f"Tags: {customer.tags}")
# Convert to protocol buffer for storage
entity_proto = customer.to_proto()
# Recreate from protocol buffer
restored_entity = Entity.from_proto(entity_proto)# Entity with comprehensive metadata
user_entity = Entity(
name="user",
value_type=ValueType.STRING,
join_keys=["user_id"],
description="Unique user identifier across all systems",
tags={
"data_classification": "internal",
"retention_policy": "7_years",
"source_system": "user_management",
"team": "identity"
},
owner="identity-team@company.com"
)
# Validate entity configuration
assert user_entity.name == "user"
assert user_entity.value_type == ValueType.STRING
assert user_entity.join_keys == ["user_id"]Install with Tessl CLI
npx tessl i tessl/pypi-feast