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.
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.3.0.tar.gz
(21.4 kB
view details)
Built Distribution
File details
Details for the file validatable-0.3.0.tar.gz
.
File metadata
- Download URL: validatable-0.3.0.tar.gz
- Upload date:
- Size: 21.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bc96bc2d1eb2c7154ef43ba9f8234f248e2f53034a75472c81b67d82787ae11 |
|
MD5 | 3c0c9e3180f01fc1c91da5093195fa56 |
|
BLAKE2b-256 | 8c2cd585ecd6b05ca3575cc23cbf2ecd0bea2c1d5fea3f7ba643d7ea0994dea8 |
File details
Details for the file validatable-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: validatable-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e6c364d292e3c55e3a0dca3e85361c7287faca43a9d1fa2c6b1141ff35bbdeb |
|
MD5 | 7969a71c9911f687a4a769c07cd9ab24 |
|
BLAKE2b-256 | 3b3b4e5014814f22fdadc701f5e520f22b55e0f9adba0c16736fba7b422c73db |