pythonadvanced
Feast Feature Store in Python
Define, materialise, and retrieve ML features using the Feast open-source feature store.
pythonPress ⌘/Ctrl + Shift + C to copy
from feast import FeatureStore, Entity, FeatureView, Field, FileSource
from feast.types import Float32, Int64
from datetime import datetime, timedelta
import pandas as pd
# Define source
data = pd.DataFrame({'user_id': [1,2,3], 'age': [25,30,35], 'purchase_count': [5,12,3], 'event_timestamp': [datetime.now()]*3, 'created': [datetime.now()]*3})
data.to_parquet('user_features.parquet', index=False)
source = FileSource(path='user_features.parquet', timestamp_field='event_timestamp')
user = Entity(name='user_id', join_keys=['user_id'])
user_fv = FeatureView(
name='user_features',
entities=[user],
ttl=timedelta(days=30),
schema=[Field(name='age', dtype=Int64), Field(name='purchase_count', dtype=Int64)],
source=source,
)
# In production: store.apply([user, user_fv]); store.materialize_incremental(end_date=datetime.now())
print('Feature view defined:', user_fv.name)
print('Features:', [f.name for f in user_fv.schema])Use Cases
- feature management
- ML pipelines
- training-serving consistency
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
pythonintermediate
Hugging Face Inference API
Run ML models via the Hugging Face Inference API for text generation, classification, and embeddings.
Best for: Text classification
#huggingface#inference
pythonintermediate
MLflow Experiment Tracking in Python
Track ML experiments, log metrics, parameters, and artefacts with MLflow for reproducible training.
Best for: experiment tracking
#mlflow#experiment-tracking
typescriptintermediate
Sortable Data Table Component
Reusable data table with column sorting, type-safe accessors, and sort direction indicators.
Best for: Admin dashboards
#table#sorting
sqlbeginner
Data Warehouse - Technique 40
Data warehouse design
Best for: database operations
#sql#database