Tecton Python SDK

1.2.13 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

Demonstrates how to initialize the Tecton client using an API key from environment variables and fetch online features from an existing Feature Service. This example requires a configured Tecton workspace and Feature Service to run successfully.

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.")

view raw JSON →