Validatable provides a single class definition for SqlAlchemy Table and Pydantic BaseModel
Project description
Validatable
Introduction
Validatable provides a single class definition for data validation and persistence in relational databases. 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 import ForeignKey, MetaData
from sqlalchemy.schema import CreateTable
from validatable import UUID4, BaseTable, EmailStr, Field
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[int] = Field(None, sa_fk=ForeignKey("user.id"))
ddl = CreateTable(User.__sa_table__)
print(ddl)
# CREATE TABLE "user" (
# id BINARY(16) NOT NULL,
# name VARCHAR,
# email VARCHAR(320),
# created_ts DATETIME NOT NULL,
# friends INTEGER NOT NULL,
# 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.1.0.tar.gz
(262.4 kB
view hashes)
Built Distribution
Close
Hashes for validatable-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bfd056edd04a3bb43c30b8014ae7262fb8560f88a81ccb21716517aea17997c |
|
MD5 | 922e13283e21c5d2e976fe9a2aeebdbc |
|
BLAKE2b-256 | 786b03c6e4301557f2d236b0a5ff41e4a17d409b3a30fba6eba4f87332452659 |