trendminer.sdk.context.type module

This module provides user-facing API’s for interacting with Context Type.

class trendminer.sdk.context.type.ContextType(key: str, name: str, workflow: ContextWorkflow | str, fields: list[trendminer.sdk.context.field.ContextField] | list[str], icon: str, color: Color | str, approvals_enabled: bool, audit_trail_enabled: bool)

Bases: ABC

A context Item is a block of information linked to a data point or a period of data associated with an event identified in the datasets. Context Item Type contains salient detail to a context data.

key

Context type unique key. Context types do not have uuids

Type:

str

name

Context type name visible to the user. Does not need to be unique

Type:

str

workflow

The workflow associated with the context type. User can provide context workflow name or unique identifier as string input

Type:

ContextWorkflow or str

fields

The context fields associated with the context type. User can provide list of context field name, key or unique identifier as string input.

Type:

list of ContextField or list of str

icon

Icon associated with the context type. List of icon names recognized in Trendminer include: ‘alert–circle’, ‘arrows–round’, ‘bucket’, ‘bucket’, ‘circle–success’, ‘clipboard’, ‘cracked’, ‘file–check’, ‘flame’, ‘flask’, ‘flow–line’, ‘information’, ‘person’, ‘ruler’, ‘snowflake’, ‘spoon’, ‘trending–down’, ‘warning’, ‘waves’, ‘waterdrops’, ‘wheelbarrow’, ‘wrench’

Type:

str

color

The color of the context type. Supports the standard format of representation defined in color library. For string input provide 3 or 6 hex digit color code. For example: ‘#f0a3ff’ for Amethyst

Type:

Color or str

approvals_enabled

Indicates whether context items of this type can be approved

Type:

bool

audit_trail_enabled

Indicates whether the edit history of context items will be saved as metadata to the item

Type:

bool

Example

# Create an implementation of context type
workflow = client.context.workflow.get_by_name('workflow_name')
field1 = client.context.field.get_by_name('field1_name')
field2 = client.context.field.get_by_name('field2_name')
context_type = client.context.type(name ='context_type_name', key="20", workflow = workflow,
icon = "information", color = "#f0a3ff", fields = [field1, field2])

# Create an implementation of context type using string imputs for context worflow and fields
context_type = client.context.type(name ='context_type_name', key="20", workflow = "workflow_name",
icon = "information", color = "#f0a3ff", fields = ['field1_name', 'field2_name'])
class trendminer.sdk.context.type.ContextTypeAPI

Bases: ABC

ContextTypeAPI class for creating and retrieving context types.

abstract get(ref: str) ContextType

Retrieves a context type from Trendminer using different retrieval methods, these methods encompass querying by context type key and name.

Note

The value of ‘ref’ will be checked with key and then name. The first matching result will be returned based on this order.

Parameters:

ref (str) –

Reference by which a unique context type can be retrieved from Trendminer such as:

  • key

  • name

Returns:

The context type pointed by the given reference. Returns the provided input directly if it’s the correct type, None, or a LazyAttribute

Return type:

ContextType

Example

# Retrieving context type  using name
context_type = client.context.type.get('context_type_name')
get_by_identifier(ref: str) ContextType

Retrieve context type by its identifier.

Parameters:

ref (str) – The unique identifier of the context type, which is not in UUID format

Returns:

The corresponding context type instance

Return type:

ContextType

Example

# Retrieving context type from an identifier
context_type = client.context.type.get_by_identifier("context_type_identifier")
get_by_key(ref: str) ContextType

Retrieve context type from its unique key.

Parameters:

ref (str) – The context item unique key

Returns:

The corresponding context type instance

Return type:

ContextType

Example

# Retrieve context type by it's key
context_type = client.context.type.get_by_key("context_type_key")
get_by_name(ref: str) ContextType

Retrieve context type from its name.

Parameters:

ref (str) – The context type name

Returns:

The corresponding context type instance

Return type:

ContextType

Example

# Retrieving context type from a name
context_type = client.context.type.get_by_name("context_type_name")
abstract list(refs: list[str]) list[trendminer.sdk.context.type.ContextType]

Retrieves a list of Context type from Trendminer using different retrieval methods, these methods encompass querying by context type key, name.

Note

Each value of input list will be checked with key, and then name, the first matching result will be returned based on this order

Parameters:

refs (list[str]) –

List of references representing unique instances on Trendminer. References by which a unique context type can be retrieved from Trendminer such as:

  • key

  • name

Returns:

List of context type retrieved from given references

Return type:

list

Example

# Retrieving list of context type
context_types = client.context.type.list(['context_type_name', 'context_type_key'])
search(*args, **kwargs) list[trendminer.sdk.context.type.ContextType]

Search context type instances by any possible Keywords type Can execute search methods for multiple Keywords described below, and return the collection of all results (without duplicates when multiple methods return overlapping instances). The wildcard character (*) can be used for flexible search queries.

Note

Atleast one of the below mentioned Keyword Arguments should be provided. Otherwise, an empty list will be returned. If multiple keywords are provided, they will be combined using an AND operation.

Keyword Arguments:
  • name (str (optional)) – Name as reference for the context type

  • key (str (optional)) – Key as reference to the context type

Returns:

List context type instances meeting the search criteria

Return type:

list

Example

# Search is performed using name for context type
context_types = client.context.type.search(name = "context_type_name")

# Search is performed using key for context type
context_types = client.context.type.search(key = "context_type_key")