{"id":3825,"library":"tecton","title":"Tecton Python SDK","description":"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.","status":"active","version":"1.2.13","language":"en","source_language":"en","source_url":"https://github.com/tecton-ai/tecton-python-sdk","tags":["feature store","mlops","data science","machine learning"],"install":[{"cmd":"pip install tecton","lang":"bash","label":"Install Tecton SDK"}],"dependencies":[],"imports":[{"symbol":"TectonClient","correct":"from tecton import TectonClient"},{"note":"Used for defining new feature views.","symbol":"FeatureView","correct":"from tecton import FeatureView"},{"note":"Used to connect to a specific Tecton workspace context.","symbol":"get_workspace","correct":"from tecton import get_workspace"},{"note":"Helper for configuring batch materialization.","symbol":"batch_materialization","correct":"from tecton import batch_materialization"},{"note":"Used for defining request-time features.","symbol":"RequestSource","correct":"from tecton import RequestSource"}],"quickstart":{"code":"import os\nfrom tecton import TectonClient\n\n# --- IMPORTANT: Setup for quickstart ---\n# 1. Set your Tecton API key as an environment variable:\n#    export TECTON_API_KEY=\"YOUR_API_KEY\"\n# 2. Replace 'your_workspace_name' with an actual workspace you have access to.\n#    (Find in Tecton UI or via `tecton list workspaces` CLI command)\n# 3. Replace 'your_feature_service_name' and 'your_join_key' with actual values.\n#    (Requires an existing FeatureService in your workspace)\n# -------------------------------------------\n\napi_key = os.environ.get('TECTON_API_KEY', '')\nif not api_key:\n    print(\"Warning: TECTON_API_KEY environment variable not set. This example will likely fail.\")\n    # In a real application, you might raise an error or exit.\n\n# Initialize the Tecton client\ntry:\n    client = TectonClient(\n        workspace_name='your_workspace_name', # e.g., 'prod'\n        api_key=api_key\n    )\n    print(f\"Successfully connected to Tecton workspace: {client.workspace_name}\")\n\n    # Example: Get online features for a specific entity.\n    # This assumes you have a FeatureService configured in your workspace.\n    # and it expects a specific join key (e.g., 'user_id').\n    feature_service_name = \"your_feature_service_name\" # e.g., 'user_transaction_counts_fs'\n    join_keys = {\"your_join_key\": \"entity_id_example\"} # e.g., {\"user_id\": \"user_123\"}\n\n    # Fetch features\n    feature_vector = client.get_online_features(\n        feature_service_name=feature_service_name,\n        join_keys=join_keys\n    )\n    \n    if feature_vector and not feature_vector.empty:\n        print(f\"\\nSuccessfully retrieved features from {feature_service_name}:\")\n        print(feature_vector.to_pandas())\n    else:\n        print(f\"\\nNo features retrieved or feature vector is empty for {feature_service_name} with join keys {join_keys}.\")\n        print(\"Please check FeatureService name, join keys, and if features are materialized.\")\n\nexcept Exception as e:\n    print(f\"\\nError during Tecton client initialization or feature retrieval: {e}\")\n    print(\"Ensure your TECTON_API_KEY is valid, workspace_name exists, and network connectivity is present.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `TECTON_API_KEY` is set in your environment (e.g., `export TECTON_API_KEY='...'`) or pass `api_key='...'` directly to `TectonClient` or `get_workspace`.","message":"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.","severity":"gotcha","affected_versions":"All"},{"fix":"Always explicitly pass the `workspace_name` parameter to `TectonClient` or `get_workspace`. Verify the workspace name matches an existing one in your Tecton deployment.","message":"Many SDK operations are context-dependent and require specifying the correct Tecton workspace name. Incorrect or non-existent workspace names will lead to errors.","severity":"gotcha","affected_versions":"All"},{"fix":"After applying feature definitions, monitor materialization jobs in the Tecton UI or via `tecton materialization monitor` CLI command. Ensure data sources are accessible and materialization schedules are configured correctly.","message":"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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}