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

pre-commit test on Linux test on MacOS PyPI - Python Version Language grade: Python PyPI - License

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.2.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

validatable-0.2.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file validatable-0.2.1.tar.gz.

File metadata

  • Download URL: validatable-0.2.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for validatable-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f091a1803f9035e1ad24a8a8ad4200577a25611df76adae87d66516bf2481683
MD5 f600f325104bd2356f17f74a3d5cede2
BLAKE2b-256 2e6be0ef1822ab1450bb345dad7f571d9e6765ba8f78b55b553e836176c29ef4

See more details on using hashes here.

File details

Details for the file validatable-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: validatable-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for validatable-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d733328e20fc8d6c22c218f4fe31a82df0395264abaae1c43aa851057f63e8d9
MD5 9cfa27d865ffa2e288a5d851d9890b91
BLAKE2b-256 7392fc63129908922136253f950c951510adb5c64ccb05aa290b0f3dd47051b1

See more details on using hashes here.

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