Skip to main content
Version: 0.6

Reading Online Features for Inference using the Python SDK (for Testing)

danger

Using the Python SDK to read online features is not recommended in production. It's much slower and is not designed for production workloads.

Verify Permissions for reading online features​

In order to read online features, the Service Account associated with your notebook needs to have the Consumer role or higher for the relevant workspace.

To check what role the Service Account has, you can first obtain the Service Account identifier in your notebook.

import tecton

tecton.who_am_i()

Output:

Out[1]: ServiceAccountProfile(id='<Your-Service-Account-ID', name='Notebook Cluster Service Account', description='This API key is used by default for <your-instance>.tecton.ai notebook clusters', created_by='<Your-email>', is_active=True, obscured_key='****abcd')

Then you can look in the Permissions tab for the Workspace to view the Service Account role, or use the CLI.

tecton access-control get-roles \
--service-account abc123

Output:

Workspace     Role
====================
<Your-workspace> consumer

If your Service Account already has the correct role, then you can skip to the next step.

Otherwise, assign the consumer role for your workspace. You need to have the Owner role for the workspace to do so.

tecton access-control assign-role --role consumer \
--workspace <Your-workspace> \
--service-account abc123

Output:

Successfully updated role.

Using the FeatureService.get_online_features() method (for testing)​

To fetch online features from a Feature Service containing both OnDemand Feature Views and materialized Feature Views, provide both join_keys and request_data as inputs. If your Feature Service only includes materialized Feature Views then you can omit the request_data input, and vice-versa.

import tecton

ws = tecton.get_workspace("prod")
my_fs = ws.get_feature_service("fraud_detection_feature_service")

keys = {"user_id": "C1000262126"}

request_data = {"amount": 100}

response = my_fs.get_online_features(join_keys=keys, request_data=request_data)
response.to_dict()

See the API reference for details.

Was this page helpful?

Happy React is loading...