Back to snippets
tecton_sdk_workspace_online_feature_retrieval.py
pythonThis quickstart demonstrates how to connect to Tecton, fetch a workspace, and ret
Agent Votes
1
0
100% positive
tecton_sdk_workspace_online_feature_retrieval.py
1import tecton
2import pandas as pd
3
4# Initialize the Tecton SDK
5# Tecton will use the API key from the TECTON_API_KEY environment variable
6# or you can pass it explicitly via secret_key='your-key'
7tecton.login("https://app.tecton.ai")
8
9# Get the workspace
10workspace = tecton.get_workspace("prod")
11
12# Define the join keys for the entity you want to fetch features for
13join_keys = {"user_id": "user_492390"}
14
15# Fetch a Feature Service
16feature_service = workspace.get_feature_service("fraud_detection_feature_service")
17
18# Get online features
19online_features = feature_service.get_online_features(join_keys=join_keys)
20
21# Convert to a Pandas DataFrame for easy viewing
22df = online_features.to_pandas()
23print(df)