Skip to content

Instantly share code, notes, and snippets.

@snfnstratcha
Created May 8, 2026 10:20
Show Gist options
  • Select an option

  • Save snfnstratcha/d7a1e958122031ae4b3131e37c4211e3 to your computer and use it in GitHub Desktop.

Select an option

Save snfnstratcha/d7a1e958122031ae4b3131e37c4211e3 to your computer and use it in GitHub Desktop.
# /// script
# requires-python = ">=3.12"
# dependencies = ["pandas", "pyarrow"]
# ///
"""
Section 1 of the article: the feature registry.
Run with:
uv run scripts/feature_store/01_registry.py
"""
from dataclasses import dataclass
from typing import Literal
@dataclass(frozen=True)
class Feature:
name: str
entity: str
dtype: Literal["int", "float", "str"]
source: str # path to a Parquet file or a SQL view
REGISTRY: dict[str, Feature] = {
"user_segment": Feature("user_segment", "user_id", "str", "data/user_segment.parquet"),
"watch_count_30d": Feature("watch_count_30d", "user_id", "int", "data/watch_count_30d.parquet"),
"last_genre": Feature("last_genre", "user_id", "str", "data/last_genre.parquet"),
}
if __name__ == "__main__":
print("Registered features:")
for name, f in REGISTRY.items():
print(f" {name:>16} entity={f.entity} dtype={f.dtype} source={f.source}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment