Tecton Python SDK
Tecton is an operational feature platform that orchestrates the entire feature lifecycle for machine learning models. The Tecton Python SDK provides tools to define, test, and deploy features, interact with the Tecton API, and retrieve feature data for online and offline use cases. Version 1.2.13 is current, with frequent minor releases.
Warnings
- gotcha Tecton SDK operations (like `TectonClient` initialization or `apply()` calls) require proper authentication, typically via a `TECTON_API_KEY` environment variable or explicit `api_key` parameter. Failing to set it will result in authentication errors.
- gotcha Many SDK operations are context-dependent and require specifying the correct Tecton workspace name. Incorrect or non-existent workspace names will lead to errors.
- gotcha Feature definitions applied via the SDK (`FeatureView.apply()`) are not immediately available for querying. They must first be materialized, which involves Tecton running data pipelines. Online feature queries will fail or return stale data if materialization is not complete or up-to-date.
Install
-
pip install tecton
Imports
- TectonClient
from tecton import TectonClient
- FeatureView
from tecton import FeatureView
- get_workspace
from tecton import get_workspace
- batch_materialization
from tecton import batch_materialization
- RequestSource
from tecton import RequestSource
Quickstart
import os
from tecton import TectonClient
# --- IMPORTANT: Setup for quickstart ---
# 1. Set your Tecton API key as an environment variable:
# export TECTON_API_KEY="YOUR_API_KEY"
# 2. Replace 'your_workspace_name' with an actual workspace you have access to.
# (Find in Tecton UI or via `tecton list workspaces` CLI command)
# 3. Replace 'your_feature_service_name' and 'your_join_key' with actual values.
# (Requires an existing FeatureService in your workspace)
# -------------------------------------------
api_key = os.environ.get('TECTON_API_KEY', '')
if not api_key:
print("Warning: TECTON_API_KEY environment variable not set. This example will likely fail.")
# In a real application, you might raise an error or exit.
# Initialize the Tecton client
try:
client = TectonClient(
workspace_name='your_workspace_name', # e.g., 'prod'
api_key=api_key
)
print(f"Successfully connected to Tecton workspace: {client.workspace_name}")
# Example: Get online features for a specific entity.
# This assumes you have a FeatureService configured in your workspace.
# and it expects a specific join key (e.g., 'user_id').
feature_service_name = "your_feature_service_name" # e.g., 'user_transaction_counts_fs'
join_keys = {"your_join_key": "entity_id_example"} # e.g., {"user_id": "user_123"}
# Fetch features
feature_vector = client.get_online_features(
feature_service_name=feature_service_name,
join_keys=join_keys
)
if feature_vector and not feature_vector.empty:
print(f"\nSuccessfully retrieved features from {feature_service_name}:")
print(feature_vector.to_pandas())
else:
print(f"\nNo features retrieved or feature vector is empty for {feature_service_name} with join keys {join_keys}.")
print("Please check FeatureService name, join keys, and if features are materialized.")
except Exception as e:
print(f"\nError during Tecton client initialization or feature retrieval: {e}")
print("Ensure your TECTON_API_KEY is valid, workspace_name exists, and network connectivity is present.")