Skip to main content
Version: 0.8

Read Online Features for Inference using the Python Client

Tecton provides an open-source client library in Python for reading features from the online store. The Python Client API Reference can be found here.

Installing the Python Client library​

The latest version of the Tecton Python Client can be found on PyPi.

For any project, install the client library using pip:

pip install tecton-client

Creating an API key to authenticate to the HTTP API​

To authenticate your requests to the HTTP API, you will need to create a Service Account to obtain an API key, and grant that Service Account the Consumer role for your workspace:

  1. Create a Service Account to obtain your API key.
tecton service-account create \
--name "sample-service-acount" \
--description "An online inference sample"

Output:

Save this API Key - you will not be able to get it again.
API Key: <Your-api-key>
Service Account ID: <Your-Service-Account-Id>
  1. Assign the Consumer role to the Service Account.
tecton access-control assign-role --role consumer \
--workspace <Your-workspace> \
--service-account <Your-Service-Account-Id>

Output:

Successfully updated role.

Save this API key for the next step.

Creating a TectonClient Object​

Create a TectonClient object with your Tecton instance base URL (https://<your Tecton instance prefix>.tecton.ai) and your API key:

tecton_client = TectonClient(url, api_key)

Calling the get-features Endpoint​

To call the get-features endpoint using the client, create objects from the GetFeaturesRequestData and GetFeaturesRequest classes.

get_features_request_data = GetFeaturesRequestData(
join_key_map={"user_id": "123", "merchant": "xyz"}, request_context_map={"amt": 500.00}
)

get_features_request = GetFeaturesRequest(
workspace_name="<Your-workspace>",
feature_service_name="fraud_detection_feature_service",
request_data=get_features_request_data,
)

Now, call the get_features() method in the tecton_client and pass the get_features_request object as a parameter.

This method:

  • Creates an HTTP request using the URL, api_key and the get_features_request object
  • Calls the FeatureService API
  • Receives the response from the API and deserializes it into the get_features_response object
get_features_response = tecton_client.get_features(get_features_request)

The feature vector can be accessed as a dictionary of feature names and their corresponding values using the property feature_values from the get_features_response.

for name, feature in get_features_response.feature_values.items():
print("Feature Name: ", name)
print("Feature Namespace: ", feature.feature_namespace)
print("Feature Name: ", feature.feature_name)
print("Feature Value: ", feature.feature_value)

# Data type of the feature value
print("Feature Value Type: ", feature.data_type)

# These two fields are only available if requested in the metadata options of the test_request
print("Feature Status: ", feature.feature_status)
print("Feature Effective Time: ", feature.effective_time)

For more information on using the client library and other functions like get-features-batch/ refer to the official documentation.

Was this page helpful?

🧠 Hi! Ask me anything about Tecton!

Floating button icon