Skip to content

API reference

Everything below is importable directly from the graphty package.

Materialization

graphty.ModelMaterializer

ModelMaterializer(
    model: type[TModel], data: FrameInitTypes | LazyFrame
)
Source code in src/graphty/materializer.py
def __init__(
    self, model: type[TModel], data: pl._typing.FrameInitTypes | pl.LazyFrame
) -> None:
    self.model = model
    self.planner = LazyFramePlanner(model=model, data=data)

Configuration

graphty.ConfigDict

Bases: ConfigDict

graphty.Opaque

Type for marking a field as opaque to the planner.

For Pydantic fields typed with Annotated[<type>, Opaque()], the GraphTy planner will forward the entire projection as a pl.Struct and otherwise ignore that field.

Disengaging the planner for a field with Opaque allows a before-validator to act on the raw bindings on the Python level.

Aggregations

graphty.Aggregation

Bases: ABC

graphty.Reduce

Reduce(
    reduction: str | Callable[..., Expr] = first, **kwargs
)

Bases: Aggregation

Source code in src/graphty/utils/aggregation.py
def __init__(
    self, reduction: str | Callable[..., pl.Expr] = pl.Expr.first, **kwargs
) -> None:
    self.reduction: Callable[..., pl.Expr] = (
        getattr(pl.Expr, reduction) if isinstance(reduction, str) else reduction
    )
    self.kwargs = kwargs

graphty.Collect

Collect(unique: bool = True, drop_nulls: bool = True)

Bases: Aggregation

Source code in src/graphty/utils/aggregation.py
def __init__(self, unique: bool = True, drop_nulls: bool = True) -> None:
    self.unique = unique
    self.drop_nulls = drop_nulls

Utilities

graphty.AliasMap

AliasMap(
    model: type[BaseModel],
    projection: set[str] | None = None,
)

Bases: UserDict

Custom mapping for resolving Pydantic field validation aliases.

E.g. for a given model

class Point(BaseModel): a: int = Field(alias="x") y: int

the mapping would compute to {"a": "x", "y": y}.

Alias choices, alias generators and alias priority are supported; alias choices are resolved against a projection.

Note that AliasPath is currently not supported.

Source code in src/graphty/utils/alias_map.py
def __init__(
    self, model: type[BaseModel], projection: set[str] | None = None
) -> None:
    self.model = model
    self.projection: set[str] = set() if projection is None else projection

    self.data = dict(self._generate_alias_map())

Exceptions

graphty.MissingGroupByError

MissingGroupByError(model: type[BaseModel])

Bases: Exception

Source code in src/graphty/utils/exceptions.py
6
7
8
9
def __init__(self, model: type[BaseModel]) -> None:
    self.model = model

    super().__init__(model)

graphty.InvalidGroupByError

InvalidGroupByError(
    model: type[BaseModel], group_by_value: str
)

Bases: Exception

Source code in src/graphty/utils/exceptions.py
def __init__(self, model: type[BaseModel], group_by_value: str) -> None:
    self.model = model
    self.group_by_value = group_by_value

    super().__init__(model, group_by_value)

graphty.MissingDiscriminatorError

MissingDiscriminatorError(type_form: TypeForm)

Bases: Exception

Source code in src/graphty/utils/exceptions.py
def __init__(self, type_form: TypeForm) -> None:
    self.type_form = type_form

    super().__init__(type_form)

graphty.AliasResolutionError

AliasResolutionError(
    field_name: str,
    model: type[BaseModel],
    aliases: list[str],
    projection: set[str],
)

Bases: Exception

Source code in src/graphty/utils/exceptions.py
def __init__(
    self,
    field_name: str,
    model: type[BaseModel],
    aliases: list[str],
    projection: set[str],
) -> None:
    self.field_name = field_name
    self.model = model
    self.aliases = aliases
    self.projection = projection

    super().__init__(field_name, model, aliases, projection)