lariat_client package
lariat_client.lariat_client
A Python module to interact with Lariat API and perform various operations like querying indicators, fetching datasets, etc.
- class lariat_client.lariat_client.Dataset(data_source: str, source_id: str, name: str, id: int, query: str, schema: Dict)
Bases:
objectA class representing a dataset in Lariat.
- Variables:
data_source (str) – The type of data source (e.g., ‘athena’).
source_id (str) – The unique ID of the data source.
name (str) – The name of the raw dataset.
schema (Dict) – The schema of the raw dataset.
- get_indicators() List[Indicator]
Gets the indicators that query this dataset.
- Returns:
A list of the indicators that query this dataset.
- Return type:
List[Indicator]
- get_schema() Dict
Gets the schema for the dataset.
- Returns:
A json representation of the dataset schema.
- Return type:
json
- class lariat_client.lariat_client.Field(dataset_id: int, name: str)
Bases:
objectA class representing a dataset’s field in Lariat.
- Variables:
dataset_id (int) – the unique ID of a dataset.
name (str) – The name of the field.
- class lariat_client.lariat_client.Filter(clauses: List[FilterClause], operator: str)
Bases:
objectA class representing a filter to use when querying metrics.
- Variables:
clauses (list) – A list of filter clauses to apply when querying metrics.
operator (str) – The operator to apply to the filter clauses. The options for this are [any, all]. The default operator is ‘all’. ‘any’ corresponds to an “OR”ing of the clauses, and ‘all’ corresponds to an “AND”ing of the clauses
- class lariat_client.lariat_client.FilterClause(field: str, operator: str, values: str | List[str])
Bases:
objectA class representing a clause to filter metrics by.
- Variables:
field (str) – The field to filter on.
operator (str) – The operator to apply to the filter values. Supported operators: [in, not_in, eq, neq]
values (list or str) – A string or list of values to filter on.
- class lariat_client.lariat_client.Indicator(id: int, dataset_id: int, dataset_name: str, query: str, aggregations: List[str], name: str, dimensions: List[str], tags: List[str])
Bases:
objectA class representing a Lariat indicator.
- Variables:
id (int) – The unique ID of the indicator.
dataset_id (int) – The unique ID of the dataset associated with the indicator.
dataset_name (str) – The name of the dataset associated with the indicator.
query (str) – The SQL query used to compute the indicator.
aggregations (List[str]) – The list of aggregation functions applied to the indicator.
name (str) – The name of the indicator.
dimensions (List[str]) – The list of dimensions used to group the indicator.
tags (List[str]) – The list of tags associated with the indicator.
- get_dimension_values(dimensions: List[str] = None) Dict[str, List[str]]
Fetches the unique values of the specified dimensions for the indicator.
- Parameters:
dimensions (List[str], optional) – The list of dimensions to fetch values for. If not provided, all dimensions will be fetched.
- Returns:
A dictionary with dimension names as keys and lists of unique values as values.
- Return type:
Dict[str, List[str]]
- class lariat_client.lariat_client.MetricRecord(evaluation_time: int, value: float, dimensions: Dict[str, str])
Bases:
objectA class representing a record returned when querying metrics.
- Variables:
evaluation_time (int) – The epoch timestamp associated with the indicator’s evaluation.
value (str) – The value of the metric at this evaluation time.
dimensions (dict) – A dictionary mapping of a metric’s dimensional names to values.
- to_dict() Dict[str, str]
Gets a dictionary representation of the metric record.
- Returns:
- A dictionary holding the evalution time, value, and
dimensions of the metric record.
- Return type:
Dict[str, str]
- class lariat_client.lariat_client.MetricRecordList(group_by_fields: List[str], records)
Bases:
objectA class representing a collection of metric records.
A MetricRecordList is printed out as a json string by default. It can be converted to a pandas dataframe via the to_df() function and can be written out as a csv via the to_csv() function.
- Variables:
group_by_fields (list) – The epoch timestamp associated with the indicator’s evaluation.
records (list) – A list of metric records returned by a query.
- to_csv(filename, header=True)
Writes the MetricRecord list to a csv.
- to_df() DataFrame
Converts the MetricRecord list into a pandas dataframe.
- Returns:
A Dataframe consisting of the metric records returned by an indicator query.
- Return type:
Pandas DataFrame
- class lariat_client.lariat_client.RawDataset(source_id: str, data_source: str, name: str, schema)
Bases:
objectA class representing a raw dataset in Lariat.
- Variables:
source_id (str) – The unique ID of the data source.
data_source (str) – The type of data source (e.g., ‘athena’).
name (str) – The name of the raw dataset.
schema (Dict) – The schema of the raw dataset.
- class lariat_client.lariat_client.RawQuery(indicator_id: int, from_ts: datetime, to_ts: datetime = None, group_by: List[str] = None, aggregate: str = None, query_filter: Filter = None, extra_args: Dict = None)
Bases:
objectA class representing a RawQuery to the Lariat metrics store.
A RawQuery may be sent to the API via raw_query.send() to retrive a MetricRecordList
- add_query_argument(key: str, value: str)
- send() MetricRecordList
- to_json() Dict
- lariat_client.lariat_client.configure(api_key: str, application_key: str)
Configures the Lariat API credentials.
- Parameters:
api_key (str) – The API key to use for authentication.
application_key (str) – The application key to use for authentication.
- lariat_client.lariat_client.get_dataset(name: str, source_id: str) Dataset | None
Gets the dataset corresponding to a given name source_id.
- Parameters:
name – The name of the dataset.
source_id – The source of the dataset.
- Returns:
A dataset corresponding to the given name and source.
- Return type:
Union[Dataset,None]
- lariat_client.lariat_client.get_datasets(name: str = None) List[Dataset]
Gets the datasets corresponding to a given name source_id.
- Parameters:
name (optional str) – The name of the dataset.
- Returns:
A list of datasets belonging to the user.
- Return type:
List[Dataset]
- lariat_client.lariat_client.get_indicator(id: int) Indicator
Gets the indicator corresponding to the provided id.
- Parameters:
id (int) – The indicator unique identifier.
- Returns:
The indicator corresponding to the provided id.
- Return type:
- lariat_client.lariat_client.get_indicators(datasets: List[Dataset] = [], tags: List[str] = [], fields: List[Field] = []) List[Indicator]
Gets the indicators corresponding to optional filters.
- Parameters:
datasets (list) – A list of datasets to get corresponding indicators for.
tags (list) – A list of tags to filter the indicators by.
fields (list) – A list of fields that the indicators should include.
- Returns:
A list of corresponding indicators.
- Return type:
List[Indicator]
- lariat_client.lariat_client.get_raw_datasets(dataset_ids: List[int]) List[RawDataset]
Gets the raw datasets given a list of dataset ids.
- Parameters:
dataset_ids (list) – A list of dataset ids to filter on.
- Returns:
A list of raw datasets that the provided dataset_ids are created from.
- Return type:
List[RawDataset]
- lariat_client.lariat_client.query(indicator_id: int, from_ts: datetime, to_ts: datetime = None, group_by: List[str] = None, aggregate: str = None, query_filter: Filter = None) MetricRecordList
Queries a provided indicator for its metric data,.
- Parameters:
indicator (indicator_id) – Indicator id to query.
from_ts (datetime.datetime) – The start time for the indicator evaluation.
to_ts (datetime.datetime) – The end time for the indicator evaluation.
group_by (list) – A list of strings to group the metrics data by.
aggregate (str) – An optional aggregation function to apply to the metric. Options for aggregate include [“sum”,”avg”,”median”,”p75”,”p25”,”max”,”min”,”count”,”distinct”]
query_filter (filter) – A filter function to apply to the metric.
- Returns:
An object that contains the list of records output by the query.
- Return type:
- lariat_client.lariat_client.query_streaming(indicator_id: str, from_ts: datetime, to_ts: datetime = None, group_by: List[str] = None, aggregate: str = None, query_filter: Filter = None) MetricRecordList
Queries a provided indicator for its metric data,.
- Parameters:
indicator (indicator_id) – Indicator id to query.
from_ts (datetime.datetime) – The start time for the indicator evaluation.
to_ts (datetime.datetime) – The end time for the indicator evaluation.
group_by (list) – A list of strings to group the metrics data by.
aggregate (str) – An optional aggregation function to apply to the metric. Options for aggregate include [“sum”,”avg”,”median”,”p75”,”p25”,”max”,”min”,”count”,”distinct”]
query_filter (filter) – A filter function to apply to the metric.
- Returns:
An object that contains the list of records output by the query.
- Return type: