Skip to main content

From type specifications to dataframe schemas

Project description

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.

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

anyschema-0.3.0.tar.gz (69.3 kB view details)

Uploaded Source

Built Distribution

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

anyschema-0.3.0-py3-none-any.whl (48.3 kB view details)

Uploaded Python 3

File details

Details for the file anyschema-0.3.0.tar.gz.

File metadata

  • Download URL: anyschema-0.3.0.tar.gz
  • Upload date:
  • Size: 69.3 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for anyschema-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6996ff27bd7ac394dcbea7de27bfe7a18b4bfe966006f971b9a2cd81a7c12928
MD5 e77bbffa466b416d9483dba57b1f5f1d
BLAKE2b-256 9793796f84901ea49f32bc89b42edd08397f0d00beecd2df3962d507d81fccb3

See more details on using hashes here.

File details

Details for the file anyschema-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: anyschema-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 48.3 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for anyschema-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5eadab81f4ae28283e59979f15641476b73215896d7e9733f6815dd960a0aa05
MD5 97a53bd2a9821b2f9d94e07de9029e26
BLAKE2b-256 3da246416515c727f3e5ee2877c968fe3c0ff91d0e07faceac7f9a128b88f101

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