Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
335 changes: 81 additions & 254 deletions schema/audience-definition-schema.json

Large diffs are not rendered by default.

Empty file.
182 changes: 36 additions & 146 deletions sdk/python/mp_audience_sdk/models/audience_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: audience-definition-schema.json
# timestamp: 2025-06-03T16:11:05+00:00
# timestamp: 2025-06-04T16:19:31+00:00

from __future__ import annotations

Expand Down Expand Up @@ -54,7 +54,7 @@ class BinaryOperator(Enum):
not_ends_with = "not_ends_with"


class AbsoluteDateOperand(BaseModel):
class AbsoluteDateExpression(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
Expand Down Expand Up @@ -103,13 +103,6 @@ class Location(BaseModel):
longitude: float


class LocationOperand(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
location: Location


class LocationOperator(Enum):
within = "within"
equals = "equals"
Expand Down Expand Up @@ -160,201 +153,98 @@ class Version(RootModel[str]):
root: str


class DateExpression1(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
operand: Union[AbsoluteDate, RelativeDate]
operator: BinaryOperator


class RelativeDateOperand(BaseModel):
class RelativeDateExpression(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
date: RelativeDate


class DateOperand(RootModel[Union[AbsoluteDateOperand, RelativeDateOperand]]):
root: Union[AbsoluteDateOperand, RelativeDateOperand] = Field(
class DateExpression(RootModel[Union[AbsoluteDateExpression, RelativeDateExpression]]):
root: Union[AbsoluteDateExpression, RelativeDateExpression] = Field(
...,
description='Represents a date value that can be either absolute or relative. Examples: 1. Absolute date: { date: { absolute: "2023-01-01T00:00:00Z" } }\n\n2. Relative date (30 days ago): { date: { relative: { offset: -30, unit: "day" } } }\n\n3. Relative date (start of current month): { date: { relative: { offset: 0, unit: "month", boundary: "start" } } }',
)


class LocationExpression1(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
operand: Location
operator: LocationOperator


class AudienceDefinition(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
audience: Expression = Field(..., title="Audience")
audience: Condition = Field(..., title="Audience")
schema_version: Version


class CountExpression1(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
operand: Operand
operator: BinaryOperator


class CountExpression2(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
expressions: List[CountExpression]
operator: LogicalOperator


class CountExpression(RootModel[Union[float, CountExpression1, CountExpression2]]):
root: Union[float, CountExpression1, CountExpression2] = Field(
...,
description='Represents a count expression, which can be a number, a binary operation, or a logical group. Examples: 1. Simple count: 5\n\n2. Binary count expression: { operator: "greater_than", operand: { path: "event.count" } }\n\n3. Logical group of count expressions: { operator: "and", expressions: [ 1, { operator: "greater_than", operand: { path: "event.count" } } ] }',
)


class DateExpression2(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
expressions: List[DateExpression]
operator: LogicalOperator


class DateExpression(
RootModel[Union[AbsoluteDate, RelativeDate, DateExpression1, DateExpression2]]
):
root: Union[AbsoluteDate, RelativeDate, DateExpression1, DateExpression2] = Field(
...,
description='Represents an expression that evaluates to a date or date-based condition. Examples: 1. Absolute date: { absolute: "2023-01-01T00:00:00Z" }\n\n2. Relative date: { relative: { offset: -30, unit: "day" } }\n\n3. Date with binary operator: { operator: "greater_than", operand: { absolute: "2023-01-01T00:00:00Z" } }\n\n4. Logical combination of dates: { operator: "and", expressions: [ { absolute: "2023-01-01T00:00:00Z" }, { operator: "less_than", operand: { relative: { offset: 0, unit: "month", boundary: "end" } } } ] }',
)


class JoinExpression(BaseModel):
class JoinCondition(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
expression: Expression
model: str


class UnaryExpression(BaseModel):
class UnaryCondition(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
operand: Operand
operand: Union[Expression, List[Expression]]
operator: UnaryOperator


class BinaryExpression(BaseModel):
class BinaryCondition(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
left: Operand
left: Union[Expression, List[Expression]]
operator: BinaryOperator
right: Operand
right: Union[Expression, List[Expression]]


class LogicalExpression(BaseModel):
class LogicalCondition(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
expressions: List[Expression]
conditions: List[Condition]
operator: LogicalOperator


class Expression(
RootModel[
Union[JoinExpression, UnaryExpression, BinaryExpression, LogicalExpression]
]
):
root: Union[
JoinExpression, UnaryExpression, BinaryExpression, LogicalExpression
] = Field(
...,
description='Represents a complex expression that can evaluate to true, false, or noop. Examples: 1. Join expression (combining expressions from different models): { "model": "user", "expression": { "operator": "equals", "left": { "path": "age" }, "right": 18 } }\n\n2. Logical expression (AND): { "operator": "and", "expressions": [ { "operator": "equals", "left": { "path": "country" }, "right": "US" }, { "operator": "greater_than", "left": { "path": "age" }, "right": 18 } ] }\n\n3. Location expression: { "operator": "within", "left": { "location": { "latitude": 37.7749, "longitude": -122.4194, "distance": { "value": 10, "unit": "miles" } } }, "right": { "model": "user", "path": "location" } }',
)


class LocationExpression2(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
expressions: List[LocationExpression]
operator: LogicalOperator


class LocationExpression(
RootModel[Union[Location, LocationExpression1, LocationExpression2]]
class Condition(
RootModel[Union[JoinCondition, UnaryCondition, BinaryCondition, LogicalCondition]]
):
root: Union[Location, LocationExpression1, LocationExpression2] = Field(
...,
description='Represents an expression that evaluates to a location or location-based condition. Examples: 1. Simple location: { latitude: 40.7128, longitude: -74.0060, distance: { value: 5, unit: "miles" } }\n\n2. Location with operator: { operator: "within", operand: { latitude: 40.7128, longitude: -74.0060, distance: { value: 5, unit: "miles" } } }\n\n3. Logical combination of locations: { operator: "or", expressions: [ { latitude: 40.7128, longitude: -74.0060, distance: { value: 5, unit: "miles" } }, { operator: "within", operand: { latitude: 34.0522, longitude: -118.2437, distance: { value: 10, unit: "miles" } } } ] }',
)


class ModelAggregationOperand(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
expression: Expression
group_by_model: str
operand: Operand
operator: AggregationOperator


class Operand(
RootModel[Union[bool, float, str, DateOperand, ModelPath, ModelAggregationOperand]]
):
root: Union[bool, float, str, DateOperand, ModelPath, ModelAggregationOperand] = (
root: Union[JoinCondition, UnaryCondition, BinaryCondition, LogicalCondition] = (
Field(
...,
description='Represents a value that can be used in expressions, including primitive values, paths, and arithmetic operations. Examples: 1. Primitive values: true 42 "hello"\n\n2. Path reference: { path: "user.age" }\n\n3. Arithmetic operation: { operator: "plus", left: { path: "price" }, right: { path: "tax" } }\n\n4. Nested arithmetic operation: { operator: "multiply", left: { operator: "plus", left: { path: "base_price" }, right: { path: "shipping" } }, right: 1.1 }\n\n5. Date operand: { date: { absolute: "2023-01-01T00:00:00Z" } }',
description='Represents a complex expression that can evaluate to true, false, or noop. Examples: 1. Join expression (combining expressions from different models): { "model": "user", "expression": { "operator": "equals", "left": { "path": "age" }, "right": 18 } }\n\n2. Logical expression (AND): { "operator": "and", "expressions": [ { "operator": "equals", "left": { "path": "country" }, "right": "US" }, { "operator": "greater_than", "left": { "path": "age" }, "right": 18 } ] }\n\n3. Location expression: { "operator": "within", "left": { "location": { "latitude": 37.7749, "longitude": -122.4194, "distance": { "value": 10, "unit": "miles" } } }, "right": { "model": "user", "path": "location" } }',
)
)


class UnaryPathExpression(BaseModel):
class ModelAggregationExpression(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
expression: PathExpression
operator: UnaryOperator


class BinaryPathExpression(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
operand: Operand
operator: BinaryOperator
condition: Condition
group_by_model: str
operand: Expression
operator: AggregationOperator


class PathExpression(
RootModel[Union[bool, float, str, UnaryPathExpression, BinaryPathExpression]]
class Expression(
RootModel[
Union[bool, float, str, DateExpression, ModelPath, ModelAggregationExpression]
]
):
root: Union[bool, float, str, UnaryPathExpression, BinaryPathExpression] = Field(
root: Union[
bool, float, str, DateExpression, ModelPath, ModelAggregationExpression
] = Field(
...,
description='Represents an expression that evaluates to a path or value. Examples: 1. Primitive values: true 42 "hello"\n\n2. Unary expression (NOT): { operator: "not", expression: { operator: "equals", operand: { path: "status" } } }\n\n3. Binary expression (comparing a path to a value): { operator: "equals", operand: { path: "user.age" } }',
description='Represents a value that can be used in expressions, including primitive values, paths, and arithmetic operations. Examples: 1. Primitive values: true 42 "hello"\n\n2. Path reference: { path: "user.age" }\n\n3. Arithmetic operation: { operator: "plus", left: { path: "price" }, right: { path: "tax" } }\n\n4. Nested arithmetic operation: { operator: "multiply", left: { operator: "plus", left: { path: "base_price" }, right: { path: "shipping" } }, right: 1.1 }\n\n5. Date operand: { date: { absolute: "2023-01-01T00:00:00Z" } }',
)


AudienceDefinition.model_rebuild()
CountExpression1.model_rebuild()
CountExpression2.model_rebuild()
DateExpression2.model_rebuild()
JoinExpression.model_rebuild()
UnaryExpression.model_rebuild()
BinaryExpression.model_rebuild()
LogicalExpression.model_rebuild()
LocationExpression2.model_rebuild()
ModelAggregationOperand.model_rebuild()
UnaryPathExpression.model_rebuild()
JoinCondition.model_rebuild()
UnaryCondition.model_rebuild()
BinaryCondition.model_rebuild()
LogicalCondition.model_rebuild()
ModelAggregationExpression.model_rebuild()
Loading