Skip to main content

anyschema: From Type Specifications to Dataframe Schemas

[!CAUTION] anyschema is still in early development and possibly unstable.


Documentation | Source Code | Issue Tracker


anyschema allows you to convert from type specifications (such as attrs classes, Pydantic models, SQLAlchemy tables, TypedDict, dataclasses, or plain Python dicts) to any dataframe schema (by "any" we intend those supported by Narwhals).

Let's see how it works in practice with an example:

from anyschema import AnySchema
from pydantic import BaseModel
from pydantic import PositiveInt


class Student(BaseModel):
    name: str
    age: PositiveInt
    classes: list[str]


schema = AnySchema(spec=Student)

# Convert to pyarrow schema
pa_schema = schema.to_arrow()

type(pa_schema)
# pyarrow.lib.Schema

pa_schema
# name: string
# age: uint64
# classes: list<item: string>
#   child 0, item: string

pl_schema = schema.to_polars()

type(pl_schema)
# polars.schema.Schema

pl_schema
# Schema([('name', String), ('age', UInt64), ('classes', List(String))])

To read more about anyschema functionalities and features consider checking out the documentation website.

Installation

anyschema is available on pypi, and it can be installed directly via any package manager. For instance:

uv pip install "anyschema[attrs]"
uv pip install "anyschema[pydantic]"
uv pip install "anyschema[sqlalchemy]"

To allow interoperability with attrs classes, Pydantic models or SQLAlchemy tables.

When to use anyschema

anyschema is designed for scenarios where type specifications (e.g., Pydantic models, SQLAlchemy tables) serve as a single source of truth for both validation and dataframe schema generation.

The typical use cases are: Data pipelines, database-to-dataframe workflows, API to database workflows, schema generation, type-safe data processing.

Why anyschema?

The project was inspired by a Talk Python podcast episode featuring the creator of LanceDB, who mentioned the need to convert from Pydantic models to PyArrow schemas.

This challenge led to a realization: such conversion could be generalized to many dataframe libraries by using Narwhals as an intermediate representation. anyschema makes this conversion seamless and extensible.

Metadata

Release files for anyschema 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anyschema 0.3.0
File Size Uploaded Provenance Actions
anyschema-0.3.0.tar.gz 69.3 kB Without provenance Details for anyschema-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for anyschema 0.3.0
File Interpreter ABI Platform Actions
anyschema-0.3.0-py3-none-any.whl Python 3 none any Details for anyschema-0.3.0-py3-none-any.whl

Total release size: 117.6 kB

Release files / anyschema-0.3.0.tar.gz

Download URL anyschema-0.3.0.tar.gz
Size 69.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6996ff27bd7ac394dcbea7de27bfe7a18b4bfe966006f971b9a2cd81a7c12928
BLAKE2b-256 checksum
How to use checksums
9793796f84901ea49f32bc89b42edd08397f0d00beecd2df3962d507d81fccb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / anyschema-0.3.0-py3-none-any.whl

Download URL anyschema-0.3.0-py3-none-any.whl
Size 48.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5eadab81f4ae28283e59979f15641476b73215896d7e9733f6815dd960a0aa05
BLAKE2b-256 checksum
How to use checksums
3da246416515c727f3e5ee2877c968fe3c0ff91d0e07faceac7f9a128b88f101
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for anyschema 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page