---
sidebar:
  label: roboto.query.conditions
  order: 2
title: roboto.query.conditions
---
## Module Contents

### Comparator

```python
class roboto.query.conditions.Comparator
```

`from roboto.query import Comparator`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L78-L187)

Bases: `roboto.compat.StrEnum`

Comparator of a condition: how it compares a field's value with the condition's value.

**Attributes**

- **Comparator.BeginsWith** = `'BEGINS_WITH'`: Field's value, a string, begins with the condition's value.

- **Comparator.Contains** = `'CONTAINS'`: Field's value, a list or string, contains the condition's value.

- **Comparator.Equals** = `'EQUALS'`: Field's value equals the condition's value.

- **Comparator.Exists** = `'EXISTS'`: Field has a value, as with `IsNotNull`.

- **Comparator.GreaterThan** = `'GREATER_THAN'`: Field's value is greater than the condition's value.

- **Comparator.GreaterThanOrEqual** = `'GREATER_THAN_OR_EQUAL'`: Field's value is greater than or equal to the condition's value.

- **Comparator.IsNotNull** = `'IS_NOT_NULL'`: Field has a value: it is present and not null.

- **Comparator.IsNull** = `'IS_NULL'`: Field has no value: it is absent or null.

- **Comparator.LessThan** = `'LESS_THAN'`: Field's value is less than the condition's value.

- **Comparator.LessThanOrEqual** = `'LESS_THAN_OR_EQUAL'`: Field's value is less than or equal to the condition's value.

- **Comparator.Like** = `'LIKE'`: Field's value, a string, matches the condition's value as a SQL `LIKE` pattern.

  In the pattern, `%` matches any run of characters, `_` matches one character, and a backslash makes the next character literal. Matching is case-sensitive.

- **Comparator.NotContains** = `'NOT_CONTAINS'`: Field's value, a list or string, does not contain the condition's value.

- **Comparator.NotEquals** = `'NOT_EQUALS'`: Field's value differs from the condition's value.

- **Comparator.NotExists** = `'NOT_EXISTS'`: Field has no value, as with `IsNull`.

- **Comparator.NotLike** = `'NOT_LIKE'`: Field's value, a string, does not match the condition's value as a SQL `LIKE` pattern.

#### Comparator.from_string()

```python
@staticmethod
def from_string(value: str) -> Comparator
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L151-L187)

Return the comparator a name, such as `GREATER_THAN`, or a symbol, such as `>`, stands for.

**Parameters**

- **value** (`str`): Comparator name, in any case, or one of the symbols `=`, `!=`, `>`, `>=`, `<`, `<=`.

**Raises**

- `ValueError`: `value` names no comparator.

**Returns**

- `Comparator`

#### Comparator.to_compact_string()

```python
def to_compact_string()
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L130-L148)

Render the comparator as its symbol, such as `>=`, or as its name, such as `CONTAINS`, if it has none.

The equality and ordering comparators have symbols: `=`, `!=`, `>`, `>=`, `<`, and `<=`.

### Condition

```python
class roboto.query.conditions.Condition(/, **data: Any)
```

`from roboto.query import Condition`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L325-L485)

Bases: `pydantic.BaseModel`

A comparison of one field of a resource with a value, the smallest part of a query's or trigger's condition.

Combine conditions with `ConditionGroup`.

**Parameters**

- **data** (`Any`)

**Attributes**

- **Condition.comparator** (`Comparator`): How to compare the field's value with `value`.

- **Condition.field** (`Annotated[str, Field]`): Path of the field to compare, such as `name` or `dataset.metadata.foo`.

  See `Field` for the resource prefixes a path can start with.

- **Condition.value** (`ConditionValue`) = `None`: Value to compare the field's value with.

  Comparators that test only whether the field has a value, such as `Comparator.Exists`, ignore it.

#### Condition.equals_cond()

```python
@classmethod
def equals_cond(field: str, value: ConditionValue) -> Condition
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L347-L354)

Build a condition that holds when a field's value equals `value`.

**Parameters**

- **field** (`str`): Path of the field to compare.
- **value** (`ConditionValue`): Value the field's value must equal.

**Returns**

- `Condition`

#### Condition.matches()

```python
def matches(target: dict) -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L369-L465)

Return whether the condition holds for a record, evaluated without a request to Roboto.

The field's value is read from `target` at the field's path within its resource, with any resource prefix removed: `dataset.metadata.foo` reads `target["metadata"]["foo"]`. Before comparing:

- A missing or `None` value makes every comparator false except those that test for no value, such as `Comparator.IsNull`. So `NotEquals` does not match a record that lacks the field.
- A string value is converted to the type of the condition's `value` when that is not a string: a number, a `decimal.Decimal`, or a datetime from an ISO 8601 string, which may end in `Z`.
- A datetime value compared with a string `value` parses `value` as ISO 8601. The condition is false when `value` does not parse, or when only one of the two datetimes has a time zone.

`Contains` and `NotContains` are false when the value is not a collection, and `BeginsWith`, `Like` and `NotLike` are false unless both the value and `value` are strings.

**Parameters**

- **target** (`dict`): Record of the resource to evaluate, as a dictionary, such as a dataset record from `model_dump()`.

**Raises**

- `ValueError`: A string value cannot be converted to the type of `value`, such as `"abc"` compared with a number.
- `TypeError`: An ordering comparator compares values that cannot be ordered, such as a number and a string.

**Returns**

- `bool`

#### Condition.target_unspecified()

```python
def target_unspecified() -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L467-L469)

Return whether the condition's field path names no resource, as `org_id` does.

**Returns**

- `bool`

#### Condition.targets_dataset()

```python
def targets_dataset() -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L471-L473)

Return whether the condition's field path names a dataset, as `dataset.name` does.

**Returns**

- `bool`

#### Condition.targets_file()

```python
def targets_file() -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L475-L477)

Return whether the condition's field path names a file, as `file.relative_path` does.

**Returns**

- `bool`

#### Condition.targets_message_path()

```python
def targets_message_path() -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L483-L485)

Return whether the condition's field path names a message path, as `msgpath.data_type` does.

**Returns**

- `bool`

#### Condition.targets_topic()

```python
def targets_topic() -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L479-L481)

Return whether the condition's field path names a topic, as `topic.name` does.

**Returns**

- `bool`

### ConditionGroup

```python
class roboto.query.conditions.ConditionGroup(/, **data: Any)
```

`from roboto.query import ConditionGroup`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L520-L588)

Bases: `pydantic.BaseModel`

A group of conditions combined by one operator, which can hold other groups.

Building a group raises `pydantic.ValidationError` when `conditions` is empty.

**Parameters**

- **data** (`Any`)

**Attributes**

- **ConditionGroup.conditions** (`collections.abc.Sequence[ConditionType]`): Conditions and nested groups to combine; at least one.
- **ConditionGroup.operator** (`ConditionOperator`): How the group combines `conditions`.

#### ConditionGroup.and_group()

```python
@staticmethod
def and_group(*conditions: ConditionType) -> ConditionGroup
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L568-L574)

Build a group that holds when every one of `conditions` holds.

**Parameters**

- **conditions** (`ConditionType`): Conditions and nested groups to combine; at least one.

**Returns**

- `ConditionGroup`

#### ConditionGroup.matches()

```python
def matches(target: dict | Callable[[ConditionType], bool])
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L532-L556)

Return whether the group holds for a record, evaluated without a request to Roboto.

Every condition in the group is evaluated, then combined by `operator`.

**Parameters**

- **target** (`dict | Callable[[ConditionType], bool]`): Record of the resource to evaluate each condition against, as a dictionary, with the same meaning as in `Condition.matches`. Or a function that takes each of the group's conditions and returns whether it holds, to evaluate them some other way.

#### ConditionGroup.or_group()

```python
@staticmethod
def or_group(*conditions: ConditionType) -> ConditionGroup
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L559-L565)

Build a group that holds when at least one of `conditions` holds.

**Parameters**

- **conditions** (`ConditionType`): Conditions and nested groups to combine; at least one.

**Returns**

- `ConditionGroup`

#### ConditionGroup.validate_conditions()

```python
def validate_conditions(v: collections.abc.Sequence[ConditionType])
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L577-L582)

Reject a group with no conditions.

**Parameters**

- **v** (`collections.abc.Sequence[ConditionType]`)

### ConditionOperator

```python
class roboto.query.conditions.ConditionOperator
```

`from roboto.query import ConditionOperator`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L488-L517)

Bases: `roboto.compat.StrEnum`

Operator of a condition group: how it combines the group's conditions.

**Attributes**

- **ConditionOperator.And** = `'AND'`: Every condition holds.
- **ConditionOperator.Not** = `'NOT'`: No condition holds.
- **ConditionOperator.Or** = `'OR'`: At least one condition holds.

#### ConditionOperator.from_string()

```python
@staticmethod
def from_string(value: str) -> ConditionOperator
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L501-L517)

Return the operator a name, such as `AND`, stands for.

**Parameters**

- **value** (`str`): `AND`, `OR`, or `NOT`, in any case.

**Raises**

- `ValueError`: `value` names no operator.

**Returns**

- `ConditionOperator`

### ConditionType

```python
roboto.query.conditions.ConditionType
```

`from roboto.query import ConditionType`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L591-L591)

Condition of any kind: one of `Condition` and `ConditionGroup`.

### ConditionValue

```python
roboto.query.conditions.ConditionValue
```

`from roboto.query import ConditionValue`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L23-L23)

Value a condition compares a field with: a string, boolean, number, `decimal.Decimal`, datetime, or `None`.

### Field

```python
class roboto.query.conditions.Field(path: str)
```

`from roboto.query import Field`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L207-L322)

Bases: `str`

A condition's field path, as a string that also holds the resource the path names.

A path that starts with `dataset.`, `file.`, `topic.` or `msgpath.` names that resource, and the rest of the path is the field within it: `dataset.metadata.foo` is the dataset field `metadata.foo`. These prefixes chain from a message path to its topic, file, and dataset, and the last prefix in the chain names the resource: `msgpath.topic.name` is the topic field `name`. A path with none of these prefixes, such as `org_id`, names no resource. The string's value is the path as written, prefixes included.

**Parameters**

- **path** (`str`): Field path, optionally starting with a resource prefix.

**Properties**

- **Field.target** (`FieldTarget`): Resource the path names, and the path to the field within that resource.

#### Field.wrap()

```python
@classmethod
def wrap(field: Union[str, Field]) -> Field
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L232-L241)

Return `field` unchanged if it is a `Field` already, or parse it into one.

**Parameters**

- **field** (`Union[str, Field]`): Field path to wrap.

**Returns**

- `Field`

### FieldTarget

```python
class roboto.query.conditions.FieldTarget
```

`from roboto.query.conditions import FieldTarget`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/query/conditions.py#L190-L204)

Bases: `NamedTuple`

A condition's field path, split into the resource it names and the path within that resource.

`Field.target` returns one.

**Attributes**

- **FieldTarget.path** (`str`): Path to the field within the resource, with a dot between nested keys, such as `metadata.foo`.

- **FieldTarget.resource** (`Literal['dataset', 'file', 'topic', 'message_path'] | None`): Resource the field path names, or `None` if it names none.

  A field whose path names no resource is read from the resource the condition is applied to, such as the one a query targets.
