API Reference
Core
- class frameright.core.FieldInfo(alias=None, ge=None, gt=None, le=None, lt=None, isin=None, regex=None, min_length=None, max_length=None, nullable=True, unique=False)[source]
Bases:
objectStores metadata for column mapping and field-level validation.
- alias
Map this attribute to a differently-named DataFrame column.
- ge
Value must be greater than or equal to this.
- gt
Value must be strictly greater than this.
- le
Value must be less than or equal to this.
- lt
Value must be strictly less than this.
- isin
Value must be one of these allowed values.
- regex
String value must match this regex pattern.
- min_length
String value must be at least this long.
- max_length
String value must be at most this long.
- nullable
Whether NaN/None values are allowed (default True).
- unique
Whether all values must be unique (default False).
- frameright.core.Field(alias=None, ge=None, gt=None, le=None, lt=None, isin=None, regex=None, min_length=None, max_length=None, nullable=True, unique=False)[source]
Helper function to define a field’s properties and constraints.
- Parameters:
alias (
Optional[str]) – Map this attribute to a differently-named DataFrame column.isin (
Optional[List[Any]]) – Value must be one of these allowed values.regex (
Optional[str]) – String value must match this regex pattern.min_length (
Optional[int]) – String value must be at least this long.max_length (
Optional[int]) – String value must be at most this long.nullable (
bool) – Whether NaN/None values are allowed (default True).unique (
bool) – Whether all values must be unique (default False).
- Return type:
- Returns:
A FieldInfo metadata object consumed by Schema during class creation.
- class frameright.core.BaseSchema(df, copy=False, validate=True, validate_types=True, coerce=False, coerce_errors='raise', strict=False)[source]
Bases:
objectBase class for the Object-DataFrame Mapper (ODM).
Define your DataFrame schema as a Python class with typed attributes. Schema validates column existence, runtime dtypes, and field-level constraints, while providing IDE-friendly autocomplete and type safety.
Do not instantiate BaseSchema directly. Use backend-specific Schema classes:
from frameright.pandas import Schema # For pandas from frameright.polars.eager import Schema # For polars eager from frameright.polars.lazy import Schema # For polars lazy
Example with pandas:
import pandas as pd from frameright.pandas import Schema, Col class Orders(Schema): order_id: Col[int] revenue: Col[float] orders = Orders(pd.DataFrame(...)) orders.revenue # Returns pd.Series orders.revenue.sum() # Use pandas methods
Example with polars:
import polars as pl from frameright.polars.eager import Schema, Col class Orders(Schema): order_id: Col[int] revenue: Col[float] orders = Orders(pl.DataFrame(...)) orders.revenue # Returns pl.Series orders.revenue.sum() # Use polars methods
Use
fr_datato access the underlying DataFrame.- fr_validate(check_types=True, strict=False)[source]
Validate column existence, runtime dtypes, and field-level constraints.
Uses Pandera for validation, with errors translated into Schema exception types (MissingColumnError, TypeMismatchError, ConstraintViolationError).
- Parameters:
- Return type:
Self- Returns:
self, for method chaining.
- Raises:
MissingColumnError – If a required column is not present.
TypeMismatchError – If a column’s dtype doesn’t match the annotation.
ConstraintViolationError – If a field-level constraint is violated.
- property fr_data: Any
Return the underlying DataFrame.
For pandas backend, returns
pd.DataFrame. For polars backend, returnspl.DataFrameorpl.LazyFrame. For narwhals backend, returnsnw.DataFrame.This property gives direct access to the DataFrame for performing operations using the backend’s native API:
# Pandas operations df.fr_data.groupby('column').sum() # Polars operations df.fr_data.filter(pl.col('x') > 5) # LazyFrame operations lazy_df.fr_data.collect()
Typing
Generic column type for Schema.
Col[T] is a generic type used for type annotations in Schema schemas.
For backend-specific imports:
- from frameright.typing.pandas import Col
- from frameright.typing.polars_eager import Col # Polars DataFrame (eager)
- from frameright.typing.polars_lazy import Col # Polars LazyFrame (lazy)
- from frameright.typing.narwhals import Col
At runtime, Col is a lightweight generic sentinel used by
__init_subclass__ to detect annotated columns. At type-check time,
it’s a generic type that allows IDE autocompletion and type hints.
Typing note: with pandas-stubs installed, type checkers can treat
Col[T] as pd.Series[T]. Other backends are best-effort because
their upstream libraries do not currently expose fully generic Series[T]
/ Expr[T] types.
Pandas-specific column types for Schema.
Use these imports when your Schema subclass wraps a pandas DataFrame:
from frameright.typing.pandas import Col
At type-check time Col[T] resolves to pd.Series[T],
giving full IDE autocomplete and static analysis.
At runtime Col is identical to the generic sentinel from
frameright.typing (used by __init_subclass__ for schema parsing).
Polars column types for Schema (compatibility shim).
- Recommended:
For eager DataFrame: from frameright.typing.polars_eager import Col
For lazy LazyFrame: from frameright.typing.polars_lazy import Col
This file exists for backward compatibility and re-exports Col as eager mode. All generic typing logic is in polars_eager and polars_lazy.
Exceptions
Custom exceptions for Schema.
- exception frameright.exceptions.StructFrameError[source]
Bases:
ExceptionBase exception for all Schema errors.
- exception frameright.exceptions.SchemaError[source]
Bases:
StructFrameErrorRaised when a schema definition is invalid.
- exception frameright.exceptions.ValidationError[source]
Bases:
StructFrameErrorRaised when DataFrame validation fails.
- exception frameright.exceptions.TypeMismatchError[source]
Bases:
ValidationErrorRaised when a column’s dtype doesn’t match the expected type.
- exception frameright.exceptions.ConstraintViolationError[source]
Bases:
ValidationErrorRaised when a field-level constraint is violated.
- exception frameright.exceptions.MissingColumnError[source]
Bases:
ValidationErrorRaised when a required column is missing from the DataFrame.