Filter module
- class Filter(*, and_list: List[Filter] | None = None, or_list: List[Filter] | None = None, fields: Dict[str, str | Comparison] | None = None)[source]
Pydantic model for handling filtering. The filter supports pythons built in “&” and “|” operators for chaining filters. The model has a to_query() method used internally to convert model to MongoDB format.
- Parameters:
fields (dict[str, Comparison]) – A dictionary of the key to be filtered on and a logical comparison.
Example
>>> from pyclarify import query >>> f1 = query.Filter(fields={"name": query.NotEqual(value="Lufttemperatur")}) >>> f2 = query.Filter(fields={"labels.unit-type": query.NotIn(value=["Flåte", "Merde 5"])}) >>> f1.to_query() ... {'name': {'$ne': 'Lufttemperatur'}} >>> f3 = f1 & f2 >>> f3.to_query() ... { ... '$and': [ ... {'name': {'$ne': 'Lufttemperatur'}}, ... {'labels.unit-type': {'$nin': ['Flåte', 'Merde 5']}} ... ] ... }
Complete list of operators can be found in pyclarify.fields.query.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'and_list': FieldInfo(annotation=Union[List[Filter], NoneType], required=False), 'fields': FieldInfo(annotation=Union[Dict[str, Union[str, Comparison]], NoneType], required=False), 'or_list': FieldInfo(annotation=Union[List[Filter], NoneType], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
Operators
- class Equal(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators | None = None)[source]
Matches using equality.
Example
>>> from pyclarify.query import Equal >>> filter_value = Equal(value="foo")
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Union[Operators, NoneType], required=False), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class Greater(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators = Operators.GT)[source]
Matches all resources where the field value is greater than the specified value.
Example
>>> from pyclarify.query import Greater >>> filter_value = Greater(value=10)
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Operators, required=False, default=<Operators.GT: '$gt'>), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class GreaterOrEqual(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators = Operators.GTE)[source]
Matches all resources where the field value is greater than or equal to the specified value.
Example
>>> from pyclarify.query import GreaterOrEqual >>> filter_value = GreaterOrEqual(value=10)
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Operators, required=False, default=<Operators.GTE: '$gte'>), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class In(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators = Operators.IN)[source]
Matches all resources where the field value is present in the specified list.
Example
>>> from pyclarify.query import In >>> filter_value = In(value=["foo", "bar"])
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Operators, required=False, default=<Operators.IN: '$in'>), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class Less(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators = Operators.LT)[source]
Matches all resources where the field value is less than the specified value.
Example
>>> from pyclarify.query import Less >>> filter_value = Less(value=10)
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Operators, required=False, default=<Operators.LT: '$lt'>), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class LessOrEqual(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators = Operators.LTE)[source]
Matches all resources where the field value is less than or equal to the specified value.
Example
>>> from pyclarify.query import LessOrEqual >>> filter_value = LessOrEqual(value=10)
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Operators, required=False, default=<Operators.LTE: '$lte'>), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class NotEqual(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators = Operators.NE)[source]
Matches using negated equality.
Example
>>> from pyclarify.query import NotEqual >>> filter_value = NotEqual(value="bar")
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Operators, required=False, default=<Operators.NE: '$ne'>), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class NotIn(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators = Operators.NIN)[source]
Matches all resources where the field value is not present in the specified list.
Example
>>> from pyclarify.query import NotIn >>> filter_value = NotIn(value=["baz", "qux"])
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Operators, required=False, default=<Operators.NIN: '$nin'>), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class Regex(*, value: str | List[str] | int | List[int] | float | List[float] | bool | None | List[None] = None, operator: Operators = Operators.REGEX)[source]
Matches all resources where the field value is match the specified regex.
Example
>>> from pyclarify.query import Regex >>> filter_value = Regex(value="fo[o]{1}")
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'operator': FieldInfo(annotation=Operators, required=False, default=<Operators.REGEX: '$regex'>), 'value': FieldInfo(annotation=Union[str, List[str], int, List[int], float, List[float], bool, NoneType, List[NoneType]], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class SelectionFormat(*, dataAsArray: bool | None = True, groupIncludedByType: bool | None = True)[source]
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'dataAsArray': FieldInfo(annotation=Union[bool, NoneType], required=False, default=True), 'groupIncludedByType': FieldInfo(annotation=Union[bool, NoneType], required=False, default=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.