utils.rcclient.entities.segment

This module provides Segment and Expression classes.

Expression classes are used to create conditions to construct segments.

Example:

expr = ItemExpression(
    field='age', operator=Operator.LESSER_OR_EQUAL, value=25
)
segment = Segment(
    name='name', description='desc',
    dataset_id='dataset_id', condition=Condition(expr),
)
segment.save()

Module Contents

Classes

AbstractExpression

The abstract base class for all expressions except GroupExpression.

ExpressionFactory

ItemExpression

A class used to build item an expression for segment.

RecipeExpression

A class used to build item an expression for segment.

BooleanExpression

A class used to build boolen expression for segment.

GlobalRefExpression

The abstract base class for all expressions except GroupExpression.

DataLabelExpression

A class used to build DataLabel expression for segment.

GroupExpression

A class used to build logical expression for segment.

Condition

A class which builds condition object for Segment.

Segment

A class which creates segment for a given dataset.

Attributes

logger

utils.rcclient.entities.segment.logger
class utils.rcclient.entities.segment.AbstractExpression

The abstract base class for all expressions except GroupExpression.

and_with(expr: ItemExpression | GroupExpression | DataLabelExpression | GlobalRefExpression | BooleanExpression) GroupExpression

Returns rcclient.entities.segment.GroupExpression object representing logical AND between two expressions. The two expressions can be any of the following types:

rcclient.entities.segment.ItemExpression rcclient.entities.segment.GroupExpression rcclient.entities.segment.DataLabelExpression rcclient.entities.segment.GlobalRefExpression rcclient.entities.segment.BooleanExpression

Parameters:

expr – Any expression type object

Returns:

An object of rcclient.entities.segment.GroupExpression

or_with(expr: ItemExpression | GroupExpression | DataLabelExpression | GlobalRefExpression | BooleanExpression) GroupExpression

Returns rcclient.entities.segment.GroupExpression object representing logical OR between two expressions. The two expressions can be any of the following types: rcclient.entities.segment.ItemExpression rcclient.entities.segment.GroupExpression rcclient.entities.segment.DataLabelExpression rcclient.entities.segment.GlobalRefExpression rcclient.entities.segment.BooleanExpression

Parameters:

expr – Any expression type object

Returns:

An object of rcclient.entities.segment.GroupExpression

class utils.rcclient.entities.segment.ExpressionFactory
property expr_type_map
get_expr(expr_type: str)
class utils.rcclient.entities.segment.ItemExpression

Bases: AbstractExpression

A class used to build item an expression for segment.

An ItemExpression is a mathematical expression composed of a variable, an operator and a value. This represents a condition which when applied to dataset creates a segment.

Example:

ItemExpression(
    field='age', operator=Operator.LESSER_OR_EQUAL, value=25
)

This will create a segment of users with age <= 25 years.

field: str
operator: utils.rcclient.enums.segment_enums.Operator
value: str
datatype: utils.rcclient.enums.segment_enums.DataType
expr_type: utils.rcclient.enums.segment_enums.ExpressionType
__post_init__()
classmethod from_(expr: utils.rcclient.dtos.response_dtos.ItemExpressionResponseDto) ItemExpression
class utils.rcclient.entities.segment.RecipeExpression

Bases: ItemExpression

A class used to build item an expression for segment.

An ItemExpression is a mathematical expression composed of a variable, an operator and a value. This represents a condition which when applied to dataset creates a segment.

Example:

ItemExpression(
    field='age', operator=Operator.LESSER_OR_EQUAL, value=25
)

This will create a segment of users with age <= 25 years.

expr_type: utils.rcclient.enums.segment_enums.ExpressionType
__post_init__()
class utils.rcclient.entities.segment.BooleanExpression

Bases: AbstractExpression

A class used to build boolen expression for segment.

A boolen expression is an expression which is either True or False.

Example:

BooleanExpression(expr_type=ExpressionType.ALWAYS_TRUE)

This will create a True expression.

expr_type: utils.rcclient.enums.segment_enums.ExpressionType
__post_init__()
classmethod from_(expr: utils.rcclient.dtos.response_dtos.SimpleExpressionResponseDto) BooleanExpression
class utils.rcclient.entities.segment.GlobalRefExpression

Bases: AbstractExpression

The abstract base class for all expressions except GroupExpression.

name: str
expr_type: utils.rcclient.enums.segment_enums.ExpressionType
__post_init__()
classmethod from_(expr: utils.rcclient.dtos.response_dtos.SimpleExpressionResponseDto) GlobalRefExpression
class utils.rcclient.entities.segment.DataLabelExpression

Bases: AbstractExpression

A class used to build DataLabel expression for segment.

A data label expression is an expression… .

Example:

DataLabelExpression(data_labels: ['dl1', 'dl2'])
data_labels: list[str]
expr_type: utils.rcclient.enums.segment_enums.ExpressionType
__post_init__()
classmethod from_(expr: utils.rcclient.dtos.response_dtos.SimpleExpressionResponseDto) DataLabelExpression
class utils.rcclient.entities.segment.GroupExpression

A class used to build logical expression for segment.

A goup expression is an expression which creates a logical expression out of 2 expressions of any type.

Example:

bool_ex = BooleanExpression(expr_type=ExpressionType.ALWAYS_TRUE)
item_ex = ItemExpression(
    field='f1', operator=Operator.EQUAL_TO, value=25
)
GroupExpression(
    group_type=GroupType.AND, group_elements=[bool_ex, item_ex]
)

This will create an expression which will do AND between bool_ex and item_ex.

group_type: utils.rcclient.enums.segment_enums.GroupType
group_elements: list[BooleanExpression | GroupExpression | ItemExpression | GlobalRefExpression | DataLabelExpression]
expr_type: utils.rcclient.enums.segment_enums.ExpressionType
expr_factory: ClassVar[ExpressionFactory]
__post_init__()
classmethod from_(expr: utils.rcclient.dtos.response_dtos.GroupExpressionResponseDto) GroupExpression
and_with(expr: ItemExpression | GroupExpression | DataLabelExpression | GlobalRefExpression | BooleanExpression) GroupExpression

This creates a logical expression which does AND operation on caller object and object passed in args. Returns a rcclient.entities.segment.GroupExpression object. If expr is None, it return the same object it was called on.

or_with(expr: ItemExpression | GroupExpression | DataLabelExpression | GlobalRefExpression | BooleanExpression) GroupExpression

This creates a logical expression which does OR operation on caller object and object passed in args. Returns a rcclient.entities.segment.GroupExpression object. If expr is None, it return the same object it was called on.

class utils.rcclient.entities.segment.Condition

A class which builds condition object for Segment.

expression: GroupExpression | ItemExpression | BooleanExpression | GlobalRefExpression | DataLabelExpression | RecipeExpression
expr_factory: ClassVar[ExpressionFactory]
__post_init__()
classmethod from_(condition: utils.rcclient.dtos.response_dtos.ConditionResponseDto) Condition
class utils.rcclient.entities.segment.Segment

A class which creates segment for a given dataset.

It requires name, description, condition and dataset_id to the constructor to create an object. This class gives the ability to perform following operations on the object:

save - Save the object.

try_it - Returns sample data of the segment.

get_data - Returns sample data of the segment.

delete - Delete the object.

Example:

expr = ItemExpression(
    field='age', operator=Operator.LESS_THAN_EQUAL, value=25
)
segment = Segment(
    name='age_less_than_25',
    description="Employees with age less than 25 years",
    codition=Condition(expr),
    dataset_id='employee_dataset_id',
    row_limit=30
)
segment.save()

Segment can also find segments by name and dataset_id using find method and get specific object by segment id using get method. find and get are classmethods and can be called on Segment class.

Example:

Segment.find(name="age_less_than_25", dataset_id='employee_dataset_id')
Segment.get('employee_segment_id')
name: str
condition: Condition
dataset_id: str
_id: str
description: str
created
row_limit: int = 10
segment_service: ClassVar[utils.rcclient.services.segment_service.SegmentService]
feature_service: ClassVar[utils.rcclient.services.feature_service.FeatureService]
__post_init__()
classmethod from_(segment_res_dto: utils.rcclient.dtos.response_dtos.SegmentResponseDto) Segment
classmethod get(_id: str) Segment
classmethod find(dataset_id: str, name: str = None) list[Segment]
add_condition(expr: ItemExpression | GlobalRefExpression | GroupExpression | DataLabelExpression | BooleanExpression) None
get_data(num_rows: int = None) utils.rcclient.dtos.response_dtos.SegmentData
try_it() utils.rcclient.dtos.response_dtos.SegmentData
save() bool
delete() None
__resolve_condition_attributes_datatype(features: Dict[str, utils.rcclient.enums.segment_enums.DataType], expr=None) None