Skip to main content

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() and from_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 .pyi stubs 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

Metadata

Release files for sqlcrucible 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlcrucible 0.5.1
File Size Uploaded Provenance Actions
sqlcrucible-0.5.1.tar.gz 166.6 kB With provenance Details for sqlcrucible-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlcrucible 0.5.1
File Interpreter ABI Platform Actions
sqlcrucible-0.5.1-py3-none-any.whl Python 3 none any Details for sqlcrucible-0.5.1-py3-none-any.whl

Total release size: 223.4 kB

Release files / sqlcrucible-0.5.1.tar.gz

Download URL sqlcrucible-0.5.1.tar.gz
Size 166.6 kB
Tags Source
SHA-256 checksum
How to use checksums
66df805774fc31a4e3cade65a760eec9926ee1d0cef15852db31e1d8d3158a1b
BLAKE2b-256 checksum
How to use checksums
f82cca75d61c8eef5d089c79341b03e8fcbdc0117f79ca8fb776c3dea21ba014
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 1, 2026.

Transparency log

Release files / sqlcrucible-0.5.1-py3-none-any.whl

Download URL sqlcrucible-0.5.1-py3-none-any.whl
Size 56.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68d8626c89fe4113ec55ce853199baf84dcd15d748074da0a610d1cee7ed177d
BLAKE2b-256 checksum
How to use checksums
bdcfab23c5834cd584faa0e9095fab898cf004b3a6496f688f2ec4a70caba4f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 1, 2026.

Transparency log

Security for sqlcrucible 0.5.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sqlcrucible-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 1, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page