Add your description here
Project description
SQLCrucible
Get the full power of Pydantic for your API and the full power of SQLAlchemy for your database, without compromising on either.
SQLCrucible lets you define a single model class that works as both a Pydantic model and a SQLAlchemy table, with explicit conversion between the two. Your Pydantic models stay pure Pydantic (working with FastAPI, validation, serialization), your SQLAlchemy models stay pure SQLAlchemy (supporting relationships, inheritance, Alembic), and conversion only happens when you ask for it.
Key Features
- Explicit conversion —
to_sa_model()andfrom_sa_model()make it clear when you're crossing the boundary between Pydantic and SQLAlchemy - Native SQLAlchemy — use
mapped_column(),relationship(), and__mapper_args__directly; if SQLAlchemy supports it, so does SQLCrucible - Escape hatches everywhere — mix with plain SQLAlchemy models, attach entities to existing tables, customize generated models, or drop down to raw queries
- Full inheritance support — single table, joined table, and concrete table inheritance all work out of the box
- Type stub generation — generate
.pyistubs for IDE autocompletion and type checking of SQLAlchemy columns - Multiple frameworks — works with Pydantic, dataclasses, and attrs
Example
from typing import Annotated
from uuid import UUID, uuid4
from pydantic import Field
from sqlalchemy import create_engine, select
from sqlalchemy.orm import Session, mapped_column
from sqlcrucible import SAType, SQLCrucibleBaseModel
class Artist(SQLCrucibleBaseModel):
__sqlalchemy_params__ = {"__tablename__": "artist"}
id: Annotated[UUID, mapped_column(primary_key=True)] = Field(default_factory=uuid4)
name: str
engine = create_engine("sqlite:///:memory:")
SAType[Artist].__table__.metadata.create_all(engine)
artist = Artist(name="Bob Dylan")
with Session(engine) as session:
session.add(artist.to_sa_model())
session.commit()
with Session(engine) as session:
sa_artist = session.scalar(
select(SAType[Artist]).where(SAType[Artist].name == "Bob Dylan")
)
artist = Artist.from_sa_model(sa_artist)
Installation
pip install sqlcrucible
Documentation
Full documentation is available at sqlcrucible.rdrj.uk.
🏴 Made with haggis
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlcrucible-0.2.3.tar.gz.
File metadata
- Download URL: sqlcrucible-0.2.3.tar.gz
- Upload date:
- Size: 133.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4987b4fee680d4d12061b11d68afbdcfb16a95aa48efdc05365c40236c6c00a
|
|
| MD5 |
3f261179de72c404c333dd8e87b34742
|
|
| BLAKE2b-256 |
287b727d58644012b446f845b5413d493548b9a436ae07844059b19865157a1f
|
Provenance
The following attestation bundles were made for sqlcrucible-0.2.3.tar.gz:
Publisher:
ci.yml on RichardDRJ/sqlcrucible
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlcrucible-0.2.3.tar.gz -
Subject digest:
a4987b4fee680d4d12061b11d68afbdcfb16a95aa48efdc05365c40236c6c00a - Sigstore transparency entry: 919966614
- Sigstore integration time:
-
Permalink:
RichardDRJ/sqlcrucible@fa46c4151a40a3a7006c7e0af99d5330b8cdaef0 -
Branch / Tag:
refs/tags/0.2.3 - Owner: https://github.com/RichardDRJ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@fa46c4151a40a3a7006c7e0af99d5330b8cdaef0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sqlcrucible-0.2.3-py3-none-any.whl.
File metadata
- Download URL: sqlcrucible-0.2.3-py3-none-any.whl
- Upload date:
- Size: 45.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2dd39ee3f644550dec8dd0add2d2f31bc801c58ffd89ebb6fdf3c3f54f1a8be
|
|
| MD5 |
64ebad14f372c863a8be84a5caedf591
|
|
| BLAKE2b-256 |
75669624215ea1200a21dfc4f8a40364b8f7044f42173780031d40602f719c89
|
Provenance
The following attestation bundles were made for sqlcrucible-0.2.3-py3-none-any.whl:
Publisher:
ci.yml on RichardDRJ/sqlcrucible
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlcrucible-0.2.3-py3-none-any.whl -
Subject digest:
d2dd39ee3f644550dec8dd0add2d2f31bc801c58ffd89ebb6fdf3c3f54f1a8be - Sigstore transparency entry: 919966621
- Sigstore integration time:
-
Permalink:
RichardDRJ/sqlcrucible@fa46c4151a40a3a7006c7e0af99d5330b8cdaef0 -
Branch / Tag:
refs/tags/0.2.3 - Owner: https://github.com/RichardDRJ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@fa46c4151a40a3a7006c7e0af99d5330b8cdaef0 -
Trigger Event:
push
-
Statement type: