Skip to main content

sqlfuse-banner-wide

Tests Coverage Last commit Issues Repo size

Python License Pydantic v2 SQLAlchemy 2

SQLFuse

A Python ORM where Pydantic validation always runs, including on database table models.

SQLFuse combines Pydantic v2 and SQLAlchemy 2 into a single class definition. You describe your data once, and you get both a fully validated Pydantic model and a real SQLAlchemy table. Validation is never skipped: it runs when objects are created, when attributes are changed, and recursively through nested relationships.

Why SQLFuse?

Using one class for both your database table and your API schema removes a lot of duplication. But if table models skip validation, invalid data can silently reach your database. SQLFuse keeps the single-class approach and makes validation a guarantee rather than an option.

Features

  • Validation that always works. Field constraints, custom field validators and model validators run on table models, both on creation and on assignment.
  • Nested validation. Building an object graph from nested data validates every level, and errors report the full path to the invalid value.
  • Relationships. One-to-many, many-to-one, many-to-many and self-referential relationships, declared with simple type annotations.
  • Nested models. Pydantic models, lists and dictionaries can be stored as JSON columns, validated when written and turned back into Pydantic objects when read.
  • Sync and async. The same models work with both synchronous and asynchronous sessions.
  • Multiple databases. PostgreSQL, MySQL and SQLite, with portable type mapping.
  • FastAPI ready. Table models can be used directly as request bodies and response models, with standard validation error responses.
  • Migrations. Built-in Alembic integration that needs no extra configuration files, plus a simple schema sync helper for development.
  • Full Pydantic field support. Every Pydantic field option is supported, alongside database column options.
  • SQLAlchemy compatible. Models are real SQLAlchemy mapped classes, so the full SQLAlchemy query API remains available.

Installation

SQLFuse is installed from PyPI. Optional extras install the drivers for PostgreSQL, MySQL or async SQLite. Python 3.10 or newer is required; it has been tested on Python 3.13 and 3.14.

Supported databases

Database Sync driver Async driver
PostgreSQL psycopg asyncpg
MySQL PyMySQL aiomysql
SQLite built-in aiosqlite

How it works

Each table model is compiled into two parts: a SQLAlchemy mapped class that owns database state, and a hidden Pydantic model that owns the validation rules. SQLFuse connects the two, so every value that enters a table model passes through Pydantic first. Rows loaded from the database are not re-validated, which keeps loading fast and means older or legacy data never fails to load.

Project status

SQLFuse is an early release (version 0.1.0). The core features are covered by an automated test suite, but the library has not yet been tested in production. Feedback and bug reports are very welcome.

Known limitations

  • Table models cannot inherit from other table models; shared fields should live in a non-table base model.
  • All table models share one registry, so two table models cannot have the same class name.
  • SQLFuse relies on some internal Pydantic APIs, so major Pydantic upgrades may require an update.

Contributing

PRs welcome

Contributions are welcome. Please open an issue to discuss bugs or ideas before submitting a pull request, and make sure the test suite passes.

License

SQLFuse is released under the MIT License.

Metadata

Release files for sqlfuse 0.1.0

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

Source distribution (sdist)

Source distribution for sqlfuse 0.1.0
File Size Uploaded Provenance Actions
sqlfuse-0.1.0.tar.gz 33.9 kB Without provenance Details for sqlfuse-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 55.7 kB

Release files / sqlfuse-0.1.0.tar.gz

Download URL sqlfuse-0.1.0.tar.gz
Size 33.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9642470d138acd6f72658e7207462af18215d73987e6bc27e7a5e4e9fc79d0f1
BLAKE2b-256 checksum
How to use checksums
43fbcadada4c0a09058862dc4a6e4ef503565a1ba24d725d49567d63df635d93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / sqlfuse-0.1.0-py3-none-any.whl

Download URL sqlfuse-0.1.0-py3-none-any.whl
Size 21.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80a52f0946eb9337d14a78b37f6e8c0dff765447ec808c9edde65e73f37dc799
BLAKE2b-256 checksum
How to use checksums
e218fce9f2700c8ccf90196870ae1c9f8e016186c6a2af41605647e1c4da66d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for sqlfuse 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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