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).

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 — see the I/O overview 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]"      # fetch_sql / write_sql helpers
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_*, SQL helpers; eager materialize_* / fetch_* 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.
  • 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
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, mypy, 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.12.0.tar.gz (306.2 kB view details)

Uploaded Source

Built Distributions

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

pydantable-1.12.0-cp313-cp313-win_arm64.whl (21.1 MB view details)

Uploaded CPython 3.13Windows ARM64

pydantable-1.12.0-cp313-cp313-macosx_11_0_arm64.whl (21.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pydantable-1.12.0-cp313-cp313-macosx_10_12_x86_64.whl (22.9 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

pydantable-1.12.0-cp312-cp312-win_amd64.whl (23.2 MB view details)

Uploaded CPython 3.12Windows x86-64

pydantable-1.12.0-cp312-cp312-musllinux_1_2_x86_64.whl (21.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pydantable-1.12.0-cp312-cp312-musllinux_1_2_aarch64.whl (19.4 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

pydantable-1.12.0-cp312-cp312-macosx_11_0_arm64.whl (21.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pydantable-1.12.0-cp312-cp312-macosx_10_12_x86_64.whl (22.9 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

pydantable-1.12.0-cp311-cp311-manylinux_2_28_aarch64.whl (22.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

pydantable-1.12.0-cp311-cp311-macosx_11_0_arm64.whl (21.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pydantable-1.12.0-cp311-cp311-macosx_10_12_x86_64.whl (22.9 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

pydantable-1.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pydantable-1.12.0.tar.gz
Algorithm Hash digest
SHA256 8a2f29e93f870cf76204488c3157f88772a73919778393b69702128a1bafe1cd
MD5 58e9cc43b900367542901f9b9b847d9d
BLAKE2b-256 1581aa418cfa523764c5b83dce0a84ac3ee7b251e3e6c6cf7f75eb3ae5bd57cc

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp313-cp313-win_arm64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 5883e16f9c7c7a6d7bb842c778bc64bb665b2051f5ec8bc6c9e841c81f48df97
MD5 0734997e122da715643a0c6ad7b0a796
BLAKE2b-256 f95e2296e57f0db7e2b1ef65c68a4b95a80ae55fdb3b37dfe63690ecacf7553d

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1e1b0f1b4c46754527217c074b4903d4e8da4603dd5c46d721a1b009160f9c7e
MD5 871b9b9076eef358a851f813f7a8bd56
BLAKE2b-256 7aab2f5f5a6b6dc970727f8b904442d3c3932afc7867715141f0ef6c17625ade

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 56503bdeaea0a81faea717e1e23e2125e2991fbe49de4a8c932c5944db96fe14
MD5 a7b4368fc36638b0d33aa944d295f1cd
BLAKE2b-256 28c4748fad26b06a63e9e8e2761f4bb6d8ddd5a0f73aa70dd46b6abf04d833c2

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1a235902742e6cd9db1228aee4ef28d84981655eea1735c20c29404d2165c276
MD5 22debca953f104c05e9b0227c7a77d20
BLAKE2b-256 ad399eda02097b267db40398b80694c10f91259a3b5f96ae1108a0abb2811ed5

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fc8307cdf82a96b0b774d61c3ab3f799a88d12a611be41eb8fce4b730c347039
MD5 35d4afbfadddd8cf53c22f4be2d0b92e
BLAKE2b-256 b7710f64edbcb6d50e3882e97e33e168813facec87314d401a2c3057b4609804

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp312-cp312-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 dcbe3718c5c0e8d648b0204df7d76f17c3cf4d66c53b5459b39d0bf026984709
MD5 d5d9779f2465cace90c957acf7962031
BLAKE2b-256 048bd01d385612bd184ff898bce71192a78851c77b6568d54830369d0335c971

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6cfbd7af7b3d1144ef593f8e64aec747d34bfdb57ca77025c138fb0488fd38ab
MD5 2a200512ca4fb64416a7b8a80a974b2c
BLAKE2b-256 731c42570bd199178fdfba4df7d3dcee760356da891e9d56c5462c1a943bc34f

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6c80f9e96d3c257160adf96bcc50131a8e70553be3e2d90102a6315d10c2373a
MD5 345f2a484077a695ce83b3b16ad1f337
BLAKE2b-256 fa4d598ae3fd01a189ddffe3cf3d9f0746860e1f9d954ae1dc8c3803e0699a70

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 065794d28148f2f07d8beb4e151419289e82eea72df6085418c83c3d61e98559
MD5 43b5d99f2ed8145473a9b7397a77d77a
BLAKE2b-256 f9e88cf09ae35406034d9ee86ae4a6813ed60b347506575e129e91f296052fe0

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9d93f9bda55b569566f884097f607577dc22bfe7a182fb939319f853a9afaf22
MD5 35b4ef6f852257a61378fb02a220c9ea
BLAKE2b-256 6a4161ece8a85640f0bdb82cd61a8668ac84e433a1f90bbd79ba3a1d9ad73b48

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 35d7ae351aeafba4b4577c5d21fb98b52ac5df77607dcbbd9bbf0fdc2246c6ff
MD5 fff7143169c5afb923d75f0dd4916c0e
BLAKE2b-256 26f7bbf766d23a2e904362d4193a702016c9c65c4274ea163f84a2a3d4688080

See more details on using hashes here.

File details

Details for the file pydantable-1.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pydantable-1.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e6266978d0a1479bab260079153063630c33f520759bbddedf663210d18a8db
MD5 ccda4be8bf2329047ba987a74f28b1e7
BLAKE2b-256 7fb9848bb6c71939e07618f50a8f4b8f06d9cd00e1d3bea49fb952cfb5fd41f6

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