Skip to main content

Validatable provides a single class definition for data validation and SQL table representation

Project description

Validatable

Data validation and SQL Toolkit using Python type hints.

CI pre-commit PyPI - Python Version Language grade: Python PyPI - License codecov coverage.py report

Introduction

Validatable provides a single class definition for data validation and SQL table representation. It uses Pydantic and SQLAlchemy Core.

Getting Started

Installation

You can install Validatable like this:

pip install validatable

Simple Example

from datetime import datetime
from typing import Optional
from uuid import uuid4

from sqlalchemy.dialects.postgresql import dialect
from sqlalchemy.schema import CreateTable

from validatable import UUID4, BaseTable, EmailStr, Field, ForeignKey, MetaData


class Base(BaseTable):
    metadata = MetaData()


class User(Base):
    id: UUID4 = Field(sa_primary_key=True, default_factory=uuid4)
    name: str
    email: EmailStr
    created_ts: datetime = Field(default_factory=datetime.now)
    friends: Optional[UUID4] = Field(sa_fk=ForeignKey("user.id"))


ddl = CreateTable(User.__sa_table__).compile(dialect=dialect())
print(ddl)

# CREATE TABLE "user" (
#         id UUID NOT NULL,
#         name VARCHAR NOT NULL,
#         email VARCHAR(320) NOT NULL,
#         created_ts TIMESTAMP WITHOUT TIME ZONE,
#         friends UUID,
#         PRIMARY KEY (id),
#         FOREIGN KEY(friends) REFERENCES "user" (id)
# )

License

This project is licensed under the terms of the MIT license - see the LICENSE.txt file for details.

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

validatable-0.4.0.tar.gz (22.2 kB view hashes)

Uploaded Source

Built Distribution

validatable-0.4.0-py3-none-any.whl (11.3 kB view hashes)

Uploaded Python 3

Supported by

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