Requests

tecton_client.requests module

This module contains classes used to build the request sent to Tecton’s API.

class tecton_client.requests.GetFeatureServiceMetadataRequest(feature_service_name: str, workspace_name: str)[source]

Bases: TectonRequest

Class representing a request to the /feature-service-metadata endpoint.

ENDPOINT

Endpoint string for the feature-service/metadata API.

Type:

str

to_json() dict[source]

Returns a JSON representation of the GetFeatureServiceMetadataRequest object as a dictionary.

class tecton_client.requests.GetFeaturesBatchRequest(workspace_name: str, feature_service_name: str, request_data_list: List[GetFeaturesRequestData], metadata_options: Set[MetadataOptions] = {MetadataOptions.DATA_TYPE, MetadataOptions.NAME}, micro_batch_size: int = 1, timeout: timedelta | None = None)[source]

Bases: AbstractGetFeaturesRequest

A class that represents a batch request to retrieve a list of feature vectors from the feature server.

The class can be used to make parallel requests to retrieve multiple feature vectors from the feature server API. The actual number of concurrent calls depends on the max_connections configuration in TectonClientOptions and the size of the connection pool.

GetFeaturesBatchRequest uses either the /get-features or the /get-features-batch endpoint depending on the configuration micro_batch_size. By default, the micro_batch_size is set to 1. It can be configured to any value in the range [1, 5].

For a GetFeaturesBatchRequest with a GetFeaturesRequestData of size n and a micro_batch_size of 1, the client enqueues n HTTP calls to be sent parallelly to the /get-features endpoint. The client waits until all calls are complete or a specific time has elapsed and returns a List of GetFeaturesResponse objects of size n.

For a GetFeaturesBatchRequest with a GetFeaturesRequestData of size n and a micro_batch_size of k where k is in the range [1, 5], the client enqueues math.ceil(n/k) microbatch requests to be sent parallelly to the /get-features-batch endpoint, waits until all microbatch requests are complete or a specific time has elapsed and returns a List of GetFeaturesResponse objects of size n.

request_list

List of GetFeaturesRequest objects or GetFeaturesMicroBatchRequest objects, based on the micro_batch_size configuration.

Type:

List[Union[GetFeaturesRequest, GetFeaturesMicroBatchRequest]]

ENDPOINT

Endpoint string for the get-features-batch API.

Type:

str

Examples

>>> request_data = GetFeaturesRequestData(join_key_map={"user_id": 1234})
>>> request = GetFeaturesBatchRequest(
...      workspace_name="my_workspace",
...      feature_service_name="my_feature_service",
...      request_data_list=[request_data, request_data],
...      metadata_options={MetadataOptions.NAME, MetadataOptions.DATA_TYPE},
...      micro_batch_size=2
...     )
>>> request.to_json_list()
    {"params": {"feature_service_name": "my_feature_service", "workspace_name": "my_workspace",
    "metadata_options": {"include_data_types": true, "include_names": true},
    "request_data": [{"join_key_map": {"user_id": 1234}}, {"join_key_map": {"user_id": 1234}}]}}
to_json_list() List[dict][source]

Returns a list of JSON representations for requests in the object as a list of dictionaries.

class tecton_client.requests.GetFeaturesRequest(workspace_name: str, feature_service_name: str, request_data: GetFeaturesRequestData, metadata_options: Set[MetadataOptions] = {MetadataOptions.DATA_TYPE, MetadataOptions.NAME})[source]

Bases: AbstractGetFeaturesRequest

Class representing a request to the /get-features endpoint.

request_data

Request parameters for the query, consisting of a Join Key Map and/or a Request Context Map sent as a GetFeaturesRequestData object.

Type:

GetFeaturesRequestData

ENDPOINT

Endpoint string for the get-features API.

Type:

str

Examples

>>> request_data = GetFeaturesRequestData(join_key_map={"user_id": 1234})
>>> get_features_request = GetFeaturesRequest("my_workspace", "my_feature_service", request_data=request_data)
>>> get_features_request.to_json()
    {"params":{"feature_service_name": "my_feature_service","workspace_name": "my_workspace",
    "metadata_options": {"include_data_types": True, "include_names": True},"join_key_map": {"user_id": 1234}}}
to_json() dict[source]

Returns a JSON representation of the GetFeaturesRequest object as a dictionary.

class tecton_client.requests.GetFeaturesRequestData(join_key_map: Dict[str, int | str | None] | None = None, request_context_map: Dict[str, int | str | float] | None = None)[source]

Bases: object

Class for request data needed for get-features queries.

join_key_map

Join keys used for Batch and Stream FeatureViews The values can be of type (int, str, type(None)) and are encoded as follows:

  1. For string keys, the value should be a string.

  2. For int keys, the value should be a string of the decimal representation of the integer.

Type:

Optional[Dict[str, Union[int, str, type(None)]]]

request_context_map

Request context used for OnDemand FeatureViews. The Request Context values can be of type (int, str, float) and are encoded as follows:

  1. For string values, the value should be a string.

  2. For int values, the value should be a string of the decimal representation of the integer.

  3. For float values, the value should be a number.

Type:

Optional[Dict[str, Union[int, str, float]]]

class tecton_client.requests.MetadataOptions(value)[source]

Bases: str, Enum

Options for retrieving metadata for get-features request.

DATA_TYPE = 'include_data_types'

Include the data types of each feature in the vector

EFFECTIVE_TIME = 'include_effective_times'

Include the timestamp of the most recent feature value that was written to the online store

FEATURE_STATUS = 'include_serving_status'

Include feature serving status information of the feature

NAME = 'include_names'

Include the name of each feature in the vector

SLO_INFO = 'include_slo_info'

Include information about the server response time

MetadataOptions(value)

Options for retrieving metadata for get-features request.

GetFeaturesRequestData([join_key_map, ...])

Class for request data needed for get-features queries.

GetFeaturesRequest(workspace_name, ...[, ...])

Class representing a request to the /get-features endpoint.

GetFeaturesBatchRequest(workspace_name, ...)

A class that represents a batch request to retrieve a list of feature vectors from the feature server.

GetFeatureServiceMetadataRequest(...)

Class representing a request to the /feature-service-metadata endpoint.