Tecton Client

tecton_client.tecton_client module

This is module consists of classes that help represent the responses from the Tecton API.

class tecton_client.tecton_client.TectonClient(url: str, api_key: str | None = None, client: ClientSession | None = None, client_options: TectonClientOptions | None = None)[source]

Bases: object

Class to represent a Tecton Client.

A TectonClient object represents a client that can be used to interact with the Tecton FeatureService API. It provides a collection of methods to make HTTP requests to the respective API endpoints and returns the response as a Python object.

Example

>>> tecton_client = TectonClient(url, api_key)
close() None[source]

Closes the client, releasing allocated resources and allowing connection reuse.

Important for proper resource management and graceful termination of the client.

get_feature_service_metadata(request: GetFeatureServiceMetadataRequest) GetFeatureServiceMetadataResponse[source]

Makes a request to the /metadata endpoint and returns the response in the form of a GetFeatureServiceMetadataResponse object.

Parameters:

request (GetFeatureServiceMetadataRequest) – The GetFeatureServiceMetadataRequest object with the request parameters.

Returns:

The GetFeatureServiceMetadataResponse object representing the

response from the HTTP API with the requested information.

Return type:

GetFeatureServiceMetadataResponse

Example

>>> tecton_client = TectonClient(url, api_key)
>>> metadata_request = GetFeatureServiceMetadataRequest(
...     feature_service_name="example_feature_service",
...     workspace_name="example_workspace",
... )
>>> metadata_response = tecton_client.get_feature_service_metadata(metadata_request)
The `metadata_response` object contains the metadata information requested as different
fields of the object.
>>> print(metadata_response.feature_values)
>>> print(metadata_response.input_join_keys)
Raises:
  • TectonClientError – If the client encounters an error while making the request.

  • UnauthorizedError – If the response returned from the Tecton Server is 401 Unauthorized, it could be because Tecton does not recognize the API Key in your request. Please refer to the API Key Documentation for more information on how to create a Service Account with an API Key

  • ForbiddenError – If the response returned from the Tecton Server is 403 Forbidden, it could be because the Service Account associated with your API Key does not have the necessary permissions to query the feature service. Please refer to the Tecton Documentation for more information.

  • NotFoundError – If the response returned from the Tecton Server is 404 Not Found. Please check the exception message for detailed information.

  • ResourcesExhaustedError – If the response returned from the Tecton Server is 429 Resources Exhausted. Please check the exception message for detailed information.

  • ServiceUnavailableError – If the response returned from the Tecton Server is 503 Service Unavailable, it could be because Tecton is currently unable to process your request. Please retry later.

  • GatewayTimeoutError – If the response returned from the Tecton Server is 504 Gateway Timeout, it indicates that processing the request exceeded the 2 seconds timeout limit set by Tecton. For more detailed information on the errors, please refer to the error responses here.

get_features(request: GetFeaturesRequest) GetFeaturesResponse[source]

Makes a request to the /get-features endpoint and returns the response in the form of a GetFeaturesResponse object

Parameters:

request (GetFeaturesRequest) – The GetFeaturesRequest object with the request parameters

Returns:

The GetFeaturesResponse object representing the response from the HTTP API

Return type:

GetFeaturesResponse

Example

>>> tecton_client = TectonClient(url, api_key)
>>> join_key_map = {"example_join_key": "example_join_value"}
>>> request_context_map = {"example_request_context": "example_string_value"}
>>> request_data = GetFeaturesRequestData(join_key_map, request_context_map)
>>> request = GetFeaturesRequest(
...     feature_service_name="example_feature_service",
...     request_data=request_data,
...     workspace_name="example_workspace",
... )
>>> response = tecton_client.get_features(request)
`response.feature_values()` returns a dictionary of {feature_name: `FeatureValue`} pairs.
To access the values of the features stored as :class:`FeatureValue` objects in the dictionary, use:
>>> print([feature.feature_value for feature in response.feature_values.values()])
[1, 2, 3, "test_feature", ["test", "array"]]
Raises:
  • BadRequestError – If the response returned from the Tecton Server is 400 Bad Request. Some of the possible reasons for this are: 1. Missing required join key in the GetFeaturesRequestData object passed in the request 2. An expected key is not found in the requestContextMap of the GetFeaturesRequestData object 3. Unexpected type for a key in the joinKeyMap passed in the GetFeaturesRequestData object 4. Unknown join key passed in the GetFeaturesRequestData object in the request

  • UnauthorizedError

    If the response returned from the Tecton Server is 401 Unauthorized, it could be because Tecton does not recognize the API Key in your request. Please refer to the API Key Documentation for more information on how to create a Service Account with an API Key

  • ForbiddenError

    If the response returned from the Tecton Server is 403 Forbidden, it could be because the Service Account associated with your API Key does not have the necessary permissions to query the feature service. Please refer to the Tecton Documentation for more information.

  • NotFoundError – If the response returned from the Tecton Server is 404 Not Found. Please check the exception message for detailed information.

  • ResourcesExhaustedError – If the response returned from the Tecton Server is 429 Resources Exhausted. Some of the possible reasons for the error are: 1. GetFeatures exceeded the concurrent request limit, please retry later 2. DynamoDB throttled the request. The request rate exceeds the AWS account’s throughput limit, or you may be requesting a hot key

  • ServiceUnavailableError – If the response returned from the Tecton Server is 503 Service Unavailable, it could be because Tecton is currently unable to process your request. Please retry later.

  • GatewayTimeoutError

    If the response returned from the Tecton Server is 504 Gateway Timeout, it indicates that processing the request exceeded the 2 seconds timeout limit set by Tecton. For more detailed information on the errors, please refer to the error responses here.

get_features_batch(request: GetFeaturesBatchRequest) GetFeaturesBatchResponse[source]

Makes a batch request to retrieve a list of feature vectors and metadata for a given workspace and feature service, and returns the response in the form of a GetFeaturesBatchResponse object.

Parameters:

request (GetFeaturesBatchRequest) – The GetFeaturesBatchRequest object with the request parameters.

Returns:

The GetFeaturesBatchResponse object representing the response from the

HTTP API, with the list of feature vectors and metadata (if requested).

Return type:

GetFeaturesBatchResponse

Example

>>> tecton_client = TectonClient(url, api_key)
>>> join_key_map = {"example_join_key": "example_join_value"}
>>> request_context_map = {"example_request_context": "example_string_value"}
>>> request_data = GetFeaturesRequestData(join_key_map, request_context_map)
>>> batch_request = GetFeaturesBatchRequest(
...     feature_service_name="example_feature_service",
...     request_data_list=[request_data, request_data],
...     workspace_name="example_workspace",
...     micro_batch_size=2
... )
>>> batch_response = tecton_client.get_features_batch(batch_request)
`batch_response.response_list` returns a list of :class:`GetFeaturesResponse` objects representing a
response for each request in the :class:`GetFeaturesBatchRequest` object.
Each :class:`GetFeaturesResponse` object contains a dictionary of {feature_name: `FeatureValue`} pairs,
which can be accessed using:
>>> for response in batch_response.response_list:
>>>     print([feature.feature_value for feature in response.feature_values.values()])
Raises:
  • TectonClientError – If the client encounters an error while making the request.

  • BadRequestError – If the response returned from the Tecton Server is 400 Bad Request. Please check the exception message for detailed information.

  • UnauthorizedError

    If the response returned from the Tecton Server is 401 Unauthorized, it could be because Tecton does not recognize the API Key in your request. Please refer to the API Key Documentation for more information on how to create a Service Account with an API Key

  • ForbiddenError

    If the response returned from the Tecton Server is 403 Forbidden, it could be because the Service Account associated with your API Key does not have the necessary permissions to query the feature service. Please refer to the Tecton Documentation for more information.

  • NotFoundError – If the response returned from the Tecton Server is 404 Not Found. Please check the exception message for detailed information.

  • ResourcesExhaustedError – If the response returned from the Tecton Server is 429 Resources Exhausted. Please check the exception message for detailed information.

  • ServiceUnavailableError – If the response returned from the Tecton Server is 503 Service Unavailable, it could be because Tecton is currently unable to process your request. Please retry later.

  • GatewayTimeoutError

    If the response returned from the Tecton Server is 504 Gateway Timeout, it indicates that processing the request exceeded the 2 seconds timeout limit set by Tecton. For more detailed information on the errors, please refer to the error responses here.

property is_closed: bool

Returns True if the client has been closed, False otherwise.

TectonClient(url[, api_key, client, ...])

Class to represent a Tecton Client.