Skip to main content

Strongly-typed DataFrames for Python, powered by Rust.

Project description

PydanTable

CI Documentation PyPI version Python versions License: MIT

Strongly typed DataFrames for Python, powered by Rust — Pydantic schemas, Polars-backed execution in the native extension, and an API built for services (including optional FastAPI integration).

Current release: 1.14.1 — highlights in the changelog.

Why PydanTable

  • One schema, many surfaces: define columns with Pydantic models; use DataFrameModel (SQLModel-style) or DataFrame[YourSchema].
  • Typed expressions: Expr and transform chains are validated and lowered in Rust; many errors fail fast at build/plan time.
  • Familiar operations: select, filter, join, group_by, windows, melt/pivot, and pandas-flavored helpers where they help.
  • Flexible materialization: row models via collect() / rows(), columnar dict[str, list], or Polars/PyArrow with the right extras.
  • I/O: lazy read_* / aread_*, streaming writes, NDJSON/JSON Lines, Parquet, CSV, IPC, HTTP, SQL (SQLModel-first fetch_sqlmodel / write_sqlmodel, explicit string SQL fetch_sql_raw / write_sql_raw, or deprecated unprefixed names) — I/O overview, IO_SQL, SQLModel roadmap, and decision tree.
  • JSON & struct columns: struct expressions, JSON encode/decode helpers, unnest/nested models — IO_JSON, SELECTORS.
  • FastAPI (optional): shared executor lifespan, NDJSON streaming from astream(), OpenAPI-friendly columnar bodies, register_exception_handlers (503 / 400 / 422). Start with the golden path and FastAPI guide.

Install

pip install pydantable

Common extras:

pip install "pydantable[polars]"   # to_polars
pip install "pydantable[arrow]"    # to_arrow / Arrow constructors
pip install "pydantable[io]"       # full file I/O convenience (arrow + polars)
pip install "pydantable[sql]"      # SQLModel + SQLAlchemy: fetch_sqlmodel, write_sqlmodel, *_raw, …
pip install "pydantable[pandas]"   # pandas-flavored façade (pandas UI doc)
pip install "pydantable[fastapi]"  # FastAPI integration (pydantable.fastapi)

Quick start

from pydantable import DataFrameModel

class User(DataFrameModel):
    id: int
    age: int | None

df = User({"id": [1, 2], "age": [20, None]})
result = (
    df.with_columns(age2=df.age * 2)
    .filter(df.age > 10)
    .select("id", "age2")
)

print(result.to_dict())
print([r.model_dump() for r in result.collect()])

Output (exact values depend on filtering; this matches scripts/verify_doc_examples.py):

{'id': [1], 'age2': [40]}
[{'id': 1, 'age2': 40}]

Core concepts

Piece Role
DataFrameModel Table class with annotated columns (class Orders(DataFrameModel): ...).
DataFrame[Schema] Generic API over your own Pydantic BaseModel.
Expr Typed expressions in with_columns, filter, etc.
Errors Ingest issues such as column length mismatch raise ColumnLengthMismatchError (ValueError subclass) from pydantable.errors — map to HTTP 400 in FastAPI via register_exception_handlers.

Static typing

  • mypy: schema-evolving return types for many chains via the bundled mypy plugin (plugins in pyproject.toml).
  • Pyright / Pylance: use committed stubs under typings/; for explicit targets, as_model(...) / try_as_model(...) / assert_model(...). See TYPING.

Rich column types (Literal, ipaddress, WKB, Annotated, …) are covered in SUPPORTED_TYPES.

Materialization: collect() / rows() → row models; to_dict()dict[str, list]; to_polars() / to_arrow() with matching extras.

I/O at a glance

  • DataFrameModel / DataFrame[Schema]: lazy read_* / aread_*, export_*, write_*, SQLModel I/O (fetch_sqlmodel, write_sqlmodel, …); eager materialize_* and SQL fetch_* / iter_* patterns live on pydantable.io — pass dict[str, list] into constructors for typed frames.
  • Scripts: raw helpers (ScanFileRoot, iterators) on pydantable.io for glue code.
  • SQL details: IO_SQL (recommended APIs, *_raw, deprecations) and SQLMODEL_SQL_ROADMAP (phased migration).
  • Large files & NDJSON patterns: IO_JSON, IO_NDJSON, EXECUTION.

Validation controls

  • Strict by default on constructors.
  • Optional ingest controls: trusted_mode, ignore_errors, on_validation_errors.
  • Missing optional fields: fill_missing_optional (default True).
  • Validation presets: validation_profile=... (or __pydantable__ = {"validation_profile": "..."}).
  • Per-column and nested strictness: {doc}STRICTNESS (field policies + profile defaults).

Documentation

Topic Link
Docs home pydantable.readthedocs.io
Map of all pages DOCS_MAP
Quickstart QUICKSTART
DataFrameModel DATAFRAMEMODEL
Typing (mypy vs Pyright) TYPING
I/O overview IO_OVERVIEW
SQL (SQLModel, raw string SQL) IO_SQL · SQLMODEL_SQL_ROADMAP
Pandas-like API PANDAS_UI
FastAPI path GOLDEN_PATH_FASTAPIFASTAPIFASTAPI_ENHANCEMENTS
Service ergonomics (OpenAPI, aliases, redaction) SERVICE_ERGONOMICS
Custom dtypes CUSTOM_DTYPES
Strictness STRICTNESS
Cookbooks Cookbook index (FastAPI, lazy pipelines, JSON logs, …)
Example multi-router app docs/examples/fastapi/service_layout/ in this repo
Test helpers pydantable.testing.fastapi — see FASTAPI
Execution & async EXECUTION · MATERIALIZATION
Behavioral contract INTERFACE_CONTRACT
Troubleshooting TROUBLESHOOTING
Versioning VERSIONING
Changelog CHANGELOG

Development

Use a virtual environment at .venv in the repo root (the Makefile defaults to .venv/bin/python). Full contributor setup, Maturin/Rust builds, and release notes: DEVELOPER.

make check-full      # ruff, ty, pyright, typing snippet tests, Sphinx, Rust

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantable-1.14.1.tar.gz (329.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantable-1.14.1-py3-none-any.whl (210.9 kB view details)

Uploaded Python 3

File details

Details for the file pydantable-1.14.1.tar.gz.

File metadata

  • Download URL: pydantable-1.14.1.tar.gz
  • Upload date:
  • Size: 329.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.13

File hashes

Hashes for pydantable-1.14.1.tar.gz
Algorithm Hash digest
SHA256 0ea9cda5ace077e2ccdf19c8a54eda746169c15d55586a90fcbc34c003d8e8e5
MD5 bafbf1dbc8c1b2636304353bc4a171bb
BLAKE2b-256 6785a7c870da4c563a41bc9b4d2cce9880b82fb3a09f36dcf117455f13133090

See more details on using hashes here.

File details

Details for the file pydantable-1.14.1-py3-none-any.whl.

File metadata

  • Download URL: pydantable-1.14.1-py3-none-any.whl
  • Upload date:
  • Size: 210.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.13

File hashes

Hashes for pydantable-1.14.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0df0ccbb46ad5b2e7403b95761fb7bbb0ca6da2dc752cc1fe05fc53831f61cd9
MD5 77fe0d70f7fcc14430a197af1cac6cd9
BLAKE2b-256 71160e7ad3aff6b6be97182dce87c5c92711d754f51930dfffdc479448995da4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page