A package that enables using Pandera DataFrame Models to validate SQL Alchemy table schemas
Project description
Pandera Alchemy
The pandera_alchemy package bridges Pandera and SQLAlchemy, allowing users to define the structure of a database table using Pandera DataFrameModels or DataFrameSchemas and validate that the table has the expected structure with SQLAlchemy.
Motivation
In modern data pipelines, ensuring that the structure of database tables matches the expected schema is crucial for maintaining data integrity and consistency. The pandera_alchemy package provides a seamless way to define and validate these structures, leveraging the power of Pandera for schema definitions and SQLAlchemy for database interactions.
Installation
To add the pandera_alchemy as a dependency to a project, add it to the project's pyproject.toml file:
Install the dependencies:
sh poetry install
Usage
See the notebook demo.ipynb for a full example of how to use the pandera_alchemy package.
Validating a Table
To validate a table, use the Table class. Below is an example of how to validate a table:
import pandera as pa
import pandera_alchemy
import sqlalchemy
class ExampleSchema(pa.DataFrameModel):
col1: str
col2: int
example_table = pandera_alchemy.Table(
name="example_table",
table_schema=ExampleSchema,
db_schema="public",
)
engine = sqlalchemy.create_engine(...)
example_table.validate(engine)
Supported Constraints
The pandera_alchemy current checks the following conditions when validating a table:
- The table exists in the database in the specified schema
- The types for all columns in the Pandera schema loosely match the types for the columns in the database. We support the following database-agnostic types: [Boolean, DateTime, Float, Integer, String, Timedelta, Date, NoneType].
- We do not distinguish between different implementations of the same logical type. For example, all implementations of Integer (Int8, Int16, UINT32, etc.) are just handled as Integer.
- Optionally, you can verify that a column's "nullable" status matches between Pandera and SQLAlchemy. This is skipped by default. To enable run
table.validate(engine, check_nullable=True)
Tests
Tests can be run with pytest:
poetry run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pandera_alchemy-1.0.0.tar.gz.
File metadata
- Download URL: pandera_alchemy-1.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7c4d20aad89ec7465fa06fa618caf214c921964a0655e1a1512dbaab04192f5
|
|
| MD5 |
fc4d4a6a6c67b6b5bfa59f284f2da618
|
|
| BLAKE2b-256 |
33ca1671c4cc974a62c7cc03777ba5468b6fe90e8132d76eeae9b34ba507a583
|
File details
Details for the file pandera_alchemy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pandera_alchemy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
629a991f583bcdfca92eb44b90a9d0283a31be417ef48a50e8725467be915b4a
|
|
| MD5 |
6ffa6eedc82e060a3422ddfe953cdbcf
|
|
| BLAKE2b-256 |
e3c592c2a6d01ce6b52f77ec0f8c66270a4b3098bb070a5b82d10e45242fc220
|