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.4.0.tar.gz
(22.2 kB
view details)
Built Distribution
File details
Details for the file validatable-0.4.0.tar.gz
.
File metadata
- Download URL: validatable-0.4.0.tar.gz
- Upload date:
- Size: 22.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01fb00350eecf102685cf9e8e9768183f9c6aed127897e73ef49b5721aae20f8 |
|
MD5 | 107953db9528b82df4e18feba6d53a49 |
|
BLAKE2b-256 | 2dc4146972a35ca9b961cc0c8380211f939cf2b2b99192a9d04eb4bf5f0e9814 |
File details
Details for the file validatable-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: validatable-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfef52e9fb881fccaf88d7c957ee6cc228bf787dcb9810a0c1baba152f2a2115 |
|
MD5 | f146054e2f3cd79897e52017b3aaca01 |
|
BLAKE2b-256 | 20632cca0a356c8e3d847c3083df5ae63fe3a4e71401c186719446cb173c51f9 |