SQL Types
Custom type decorators for SQLModel/SQLAlchemy with Pydantic validation
Installation
pip install sqltypes
Quick Start
from typing import Sequence
from pydantic import BaseModel
from sqlmodel import Field, SQLModel
from sqltypes import ValidatedJSON, SpaceDelimitedList
class User(BaseModel):
name: str
age: int
class Article(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
tags: Sequence[str] = Field(sa_type=SpaceDelimitedList)
author: User = Field(sa_type=ValidatedJSON(User))
Available Types
ValidatedJSON(T, name?)
Stores any Pydantic model or complex type as JSON with automatic validation.
config: Config = Field(sa_type=ValidatedJSON(Config))
SpaceDelimitedList
Stores sequences as space-delimited strings.
tags: Sequence[str] = Field(sa_type=SpaceDelimitedList)
# Database: "python sql database"
# Python: ["python", "sql", "database"]
ValidatedStr(LiteralType)
Validates strings against Pydantic literal types.
from typing import Literal
Status = Literal["pending", "active", "completed"]
status: Status = Field(sa_type=ValidatedStr(Status))
Custom Types
Use CustomTypeMeta to create your own types:
from sqltypes import CustomTypeMeta
from sqlalchemy.types import String
CommaSeparatedList = CustomTypeMeta(
'CommaSeparatedList',
(), {},
Impl=String,
dump=lambda lst: ','.join(lst),
parse=lambda s: s.split(',')
)
Or use CustomStringMeta for string-based types:
from sqltypes import CustomStringMeta
class CommaSeparatedList(metaclass=CustomStringMeta,
dump=lambda lst: ','.join(lst),
parse=lambda s: s.split(',')):
...
Links
- PyPI: https://pypi.org/project/sqltypes/
- Repository: https://github.com/marciclabas/sqltypes
Metadata
Release files for sqltypes 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqltypes-0.1.11.tar.gz | 3.1 kB | Without provenance | Details for sqltypes-0.1.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqltypes-0.1.11-py3-none-any.whl | Python 3 | none | any | Details for sqltypes-0.1.11-py3-none-any.whl |
Total release size: 7.1 kB
Release files / sqltypes-0.1.11.tar.gz
| Download URL | sqltypes-0.1.11.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ee94b4f5dcd37de58dfeae84cd3d06e6e680f7debd2010667af92d1c7156b5f
|
|
BLAKE2b-256 checksum How to use checksums |
78b64f3ef66099f9df692168cfedf69656ac12635fedf08cfa233ddf0e078a14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.10
|
Release files / sqltypes-0.1.11-py3-none-any.whl
| Download URL | sqltypes-0.1.11-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
45cabbe32801e866e63c2a26dff70cd8492c958ea7379739753da466191d51e4
|
|
BLAKE2b-256 checksum How to use checksums |
af2f35d88656f4034b5b68382baba73abd68c1f59b629c32716d7377a41a0e17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.10
|
Security for sqltypes 0.1.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.