Metrics

This exports the metrics module from the peak package.

class peak.metrics.Metric(session=None)

Client class for interacting with metrics resource.

Parameters:

session (Session) –

create_collection(artifact, body)

Create Metric Collection.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • body (Dict[str, Any]) – A dictionary containing the details to publish the metrics.

  • artifact (ArtifactInfo) – Mapping of artifact attributes that specifies how the artifact will be generated, it accepts one key path,

Returns:

A dictionary containing details about the published metrics.

Return type:

Dict[str, Any]

SCHEMA:
{
  "name": "string",
  "scope": "string",
  "description": "string"
}
Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • artifact (ArtifactInfo) –

  • body (Dict[str, Any]) –

Return type:

Dict[str, Any]

delete(*, namespace=None, measures=None, publication_id=None)

Delete one or more measures.

The measures can be deleted either by passing publication_id in which case all metrics related to the publication will be deleted. Or by passing namespace and measures in which case only the specified measures will be deleted. If both are passed, publication_id takes priority.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • namespace (str) – The namespace to delete the measures from. Required if measures is passed.

  • measures (List[str]) – An array of measures to delete.

  • publication_id (str) – The publication ID to delete. Passing this will delete all the metrics in the publication.

Returns:

An empty dictionary.

Return type:

Dict[str, Any]

Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

delete_collection(collection_id)

Delete a metric collection.

REFERENCE:

πŸ”— API Documentation

Parameters:

collection_id (str) – The ID of the collection to delete.

Returns:

A dictionary containing details about the deleted collection.

Return type:

Dict[str, Any]

Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

list(page_size: int | None = None, page_number: int | None = None, namespace: str | None = None, type: str | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list(page_size: int | None = None, page_number: int | None = None, namespace: str | None = None, type: str | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Retrieve the list of metrics.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • page_size (int | None) – The number of images per page.

  • page_number (int | None) – The page number to retrieve. Only used when return_iterator is False.

  • namespace (str | None) – The namespace associated with the metrics. If not provided, the default namespace is used.

  • type (str | None) – The type of metrics to retrieve. If not provided, all metrics are retrieved. Available types are cube, view, dimension, measure, segment and all.

  • return_iterator (bool) – Whether to return an iterator object or list of metrics for a specified page number, defaults to True.

Returns:

an iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any]] | Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • InternalServerErrorException – The server failed to process the request.

list_collections(page_size: int | None = None, page_number: int | None = None, id: List[str] | None = None, scope: List[str] | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list_collections(page_size: int | None = None, page_number: int | None = None, id: List[str] | None = None, scope: List[str] | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Retrieve the list of metric collections.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • page_size (int | None) – The number of images per page.

  • page_number (int | None) – The page number to retrieve. Only used when return_iterator is False.

  • id (List[str] | None) – An array of collection IDs to retrieve. If not provided, all collections are retrieved.

  • scope (List[str] | None) – An array of scopes to filter the collections by. Available scopes are PUBLIC and PRIVATE. If not provided, all collections of the tenant along with all public collections are retrieved.

  • return_iterator (bool) – Whether to return an iterator object or list of metrics for a specified page number, defaults to True.

Returns:

an iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any]] | Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • InternalServerErrorException – The server failed to process the request.

list_namespaces(page_size: int | None = None, page_number: int | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list_namespaces(page_size: int | None = None, page_number: int | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Retrieve the list of namespaces.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • page_size (int | None) – The number of images per page.

  • page_number (int | None) – The page number to retrieve. Only used when return_iterator is False.

  • return_iterator (bool) – Whether to return an iterator object or list of metrics for a specified page number, defaults to True.

Returns:

an iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any]] | Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • InternalServerErrorException – The server failed to process the request.

publish(artifact=None, collection_id=None, body=None)

Publish Metrics.

The metrics can be published either by passing artifact and namespace, or by passing collection_id and namespace. If both artifact and collection_id are provided, artifact takes priority. If the namespace is not provided, the β€˜default’ namespace is used.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • body (Dict[str, Any]) – A dictionary containing the details to publish the metrics.

  • artifact (ArtifactInfo | None) – Mapping of artifact attributes that specifies how the artifact will be generated, it accepts one key path,

  • collection_id (str | None) – The ID of the collection to publish the metrics.

Returns:

A dictionary containing details about the published metrics.

Return type:

Dict[str, Any]

SCHEMA:
{
  "namespace": "string",
}
Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • artifact (ArtifactInfo | None) –

  • collection_id (str | None) –

  • body (Dict[str, Any] | None) –

Return type:

Dict[str, Any]

query(measures, namespace=None, generate_sql=False, dimensions=None, filters=None, time_dimensions=None, segments=None, order=None, limit=None, offset=None)

Query a published metric in the semantic layer using the provided parameters.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • measures (List[str]) – An array of measures to include in the query. Measures represent quantitative metrics such as sums or counts.

  • namespace (str | None) – The namespace associated with the metrics. If not provided, the default namespace is used.

  • generate_sql (bool | None) – Indicates whether to return the SQL query instead of data. If true, the response will include the SQL query used to retrieve the metrics. Default is false.

  • dimensions (List[str] | None) – An array of dimensions to include in the query. Dimensions represent qualitative categories such as time, location, or product names.

  • filters (List[Dict[str, Any]] | None) – An array of filter objects to apply to the query. Filters limit the data returned based on specific conditions. dimension (str): The dimension to filter on. operator (str): The operator to use for the filter. Supported values are equals, notEquals, contains, notContains, startsWith, notStartsWith, endsWith, notEndsWith, gt, gte, lt, lte, inDateRange, notInDateRange, beforeDate, beforeOrOnDate, afterDate, afterOrOnDate etc. values (List[str]): An array of values to filter on.

  • time_dimensions (List[Dict[str, Any]] | None) – Time dimensions allow querying over specific time ranges with optional granularity (e.g., day, month, year). dimension (str): The time dimension to include in the query. granularity (str | None): The granularity of the time dimension. Supported values are second, minute, hour, day, week, month, quarter, and year. dateRange (list(str) | str | None): An array of two dates that define the time range for the query. Alternatively, you can provide a single string out of the following predefined date ranges today, yesterday, this week, last week, this month, last month, this quarter, last quarter, this year, last year, last 7 days and last 30 days.

  • segments (List[str] | None) – An array of segments to include in the query. Segments represent pre-defined filters that can be applied to metrics.

  • order (Dict[str, Any] | None) – Defines the sort order of the results. This is an object where keys are the dimensions/measures and values are either β€˜asc’ or β€˜desc’ to specify ascending or descending order.

  • limit (int | None) – Limits the number of rows returned by the query. If not provided, the default limit is applied.

  • offset (int | None) – Specifies the number of rows to skip before starting to return data. Useful for pagination.

Returns:

A dictionary containing the query metrics response.

Return type:

Dict[str, Any]

Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

peak.metrics.get_client(session=None)

Returns a Metrics client, If no session is provided, a default session is used.

Parameters:

session (Optional[Session]) – A Session Object. Default is None.

Returns:

The metric client object.

Return type:

Metric

Metric Client

class peak.metrics.Metric(session=None)

Client class for interacting with metrics resource.

Parameters:

session (Session) –

create_collection(artifact, body)

Create Metric Collection.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • body (Dict[str, Any]) – A dictionary containing the details to publish the metrics.

  • artifact (ArtifactInfo) – Mapping of artifact attributes that specifies how the artifact will be generated, it accepts one key path,

Returns:

A dictionary containing details about the published metrics.

Return type:

Dict[str, Any]

SCHEMA:
{
  "name": "string",
  "scope": "string",
  "description": "string"
}
Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • artifact (ArtifactInfo) –

  • body (Dict[str, Any]) –

Return type:

Dict[str, Any]

delete(*, namespace=None, measures=None, publication_id=None)

Delete one or more measures.

The measures can be deleted either by passing publication_id in which case all metrics related to the publication will be deleted. Or by passing namespace and measures in which case only the specified measures will be deleted. If both are passed, publication_id takes priority.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • namespace (str) – The namespace to delete the measures from. Required if measures is passed.

  • measures (List[str]) – An array of measures to delete.

  • publication_id (str) – The publication ID to delete. Passing this will delete all the metrics in the publication.

Returns:

An empty dictionary.

Return type:

Dict[str, Any]

Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

delete_collection(collection_id)

Delete a metric collection.

REFERENCE:

πŸ”— API Documentation

Parameters:

collection_id (str) – The ID of the collection to delete.

Returns:

A dictionary containing details about the deleted collection.

Return type:

Dict[str, Any]

Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

list(page_size: int | None = None, page_number: int | None = None, namespace: str | None = None, type: str | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list(page_size: int | None = None, page_number: int | None = None, namespace: str | None = None, type: str | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Retrieve the list of metrics.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • page_size (int | None) – The number of images per page.

  • page_number (int | None) – The page number to retrieve. Only used when return_iterator is False.

  • namespace (str | None) – The namespace associated with the metrics. If not provided, the default namespace is used.

  • type (str | None) – The type of metrics to retrieve. If not provided, all metrics are retrieved. Available types are cube, view, dimension, measure, segment and all.

  • return_iterator (bool) – Whether to return an iterator object or list of metrics for a specified page number, defaults to True.

Returns:

an iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any]] | Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • InternalServerErrorException – The server failed to process the request.

list_collections(page_size: int | None = None, page_number: int | None = None, id: List[str] | None = None, scope: List[str] | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list_collections(page_size: int | None = None, page_number: int | None = None, id: List[str] | None = None, scope: List[str] | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Retrieve the list of metric collections.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • page_size (int | None) – The number of images per page.

  • page_number (int | None) – The page number to retrieve. Only used when return_iterator is False.

  • id (List[str] | None) – An array of collection IDs to retrieve. If not provided, all collections are retrieved.

  • scope (List[str] | None) – An array of scopes to filter the collections by. Available scopes are PUBLIC and PRIVATE. If not provided, all collections of the tenant along with all public collections are retrieved.

  • return_iterator (bool) – Whether to return an iterator object or list of metrics for a specified page number, defaults to True.

Returns:

an iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any]] | Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • InternalServerErrorException – The server failed to process the request.

list_namespaces(page_size: int | None = None, page_number: int | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list_namespaces(page_size: int | None = None, page_number: int | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Retrieve the list of namespaces.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • page_size (int | None) – The number of images per page.

  • page_number (int | None) – The page number to retrieve. Only used when return_iterator is False.

  • return_iterator (bool) – Whether to return an iterator object or list of metrics for a specified page number, defaults to True.

Returns:

an iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any]] | Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • InternalServerErrorException – The server failed to process the request.

publish(artifact=None, collection_id=None, body=None)

Publish Metrics.

The metrics can be published either by passing artifact and namespace, or by passing collection_id and namespace. If both artifact and collection_id are provided, artifact takes priority. If the namespace is not provided, the β€˜default’ namespace is used.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • body (Dict[str, Any]) – A dictionary containing the details to publish the metrics.

  • artifact (ArtifactInfo | None) – Mapping of artifact attributes that specifies how the artifact will be generated, it accepts one key path,

  • collection_id (str | None) – The ID of the collection to publish the metrics.

Returns:

A dictionary containing details about the published metrics.

Return type:

Dict[str, Any]

SCHEMA:
{
  "namespace": "string",
}
Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • artifact (ArtifactInfo | None) –

  • collection_id (str | None) –

  • body (Dict[str, Any] | None) –

Return type:

Dict[str, Any]

query(measures, namespace=None, generate_sql=False, dimensions=None, filters=None, time_dimensions=None, segments=None, order=None, limit=None, offset=None)

Query a published metric in the semantic layer using the provided parameters.

REFERENCE:

πŸ”— API Documentation

Parameters:
  • measures (List[str]) – An array of measures to include in the query. Measures represent quantitative metrics such as sums or counts.

  • namespace (str | None) – The namespace associated with the metrics. If not provided, the default namespace is used.

  • generate_sql (bool | None) – Indicates whether to return the SQL query instead of data. If true, the response will include the SQL query used to retrieve the metrics. Default is false.

  • dimensions (List[str] | None) – An array of dimensions to include in the query. Dimensions represent qualitative categories such as time, location, or product names.

  • filters (List[Dict[str, Any]] | None) – An array of filter objects to apply to the query. Filters limit the data returned based on specific conditions. dimension (str): The dimension to filter on. operator (str): The operator to use for the filter. Supported values are equals, notEquals, contains, notContains, startsWith, notStartsWith, endsWith, notEndsWith, gt, gte, lt, lte, inDateRange, notInDateRange, beforeDate, beforeOrOnDate, afterDate, afterOrOnDate etc. values (List[str]): An array of values to filter on.

  • time_dimensions (List[Dict[str, Any]] | None) – Time dimensions allow querying over specific time ranges with optional granularity (e.g., day, month, year). dimension (str): The time dimension to include in the query. granularity (str | None): The granularity of the time dimension. Supported values are second, minute, hour, day, week, month, quarter, and year. dateRange (list(str) | str | None): An array of two dates that define the time range for the query. Alternatively, you can provide a single string out of the following predefined date ranges today, yesterday, this week, last week, this month, last month, this quarter, last quarter, this year, last year, last 7 days and last 30 days.

  • segments (List[str] | None) – An array of segments to include in the query. Segments represent pre-defined filters that can be applied to metrics.

  • order (Dict[str, Any] | None) – Defines the sort order of the results. This is an object where keys are the dimensions/measures and values are either β€˜asc’ or β€˜desc’ to specify ascending or descending order.

  • limit (int | None) – Limits the number of rows returned by the query. If not provided, the default limit is applied.

  • offset (int | None) – Specifies the number of rows to skip before starting to return data. Useful for pagination.

Returns:

A dictionary containing the query metrics response.

Return type:

Dict[str, Any]

Raises:
  • InvalidParameterException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given feature does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.