SQLAlchemy Partial Tables
Partial Tables for SQLAlchemy and SQLModel
Installation
pip install partial-tables
Scenario
Let's say you have 2 tables, business_draft and business.
business_draft and business have the same fields, but business_draft should allow most fields to be nullable.
Any business can freely update its draft, but only approved modifications get copied over to business.
How can we implement this and reduce redundancy?
Usage
Any field marked with PartialAllowed will be nullable in the partial table, and required in the complete table.
A partial table is any table that sub-classes with PartialTable.
Example (SQLAlchemy Declarative)
from typing import Annotated
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from partial_tables import PartialSQLAlchemyMixin, PartialAllowed, PartialTable
class Base(DeclarativeBase):
__abstract__ = True
class BusinessBase(PartialSQLAlchemyMixin, Base):
"""Base class for all business models."""
__abstract__ = True
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
business_name: Mapped[str] = mapped_column()
# Mark fields that may be nullable in the partial table
city: Mapped[Annotated[str, PartialAllowed()]] = mapped_column()
address: Mapped[Annotated[str, PartialAllowed()]] = mapped_column()
class BusinessDraft(BusinessBase, PartialTable):
__tablename__ = "business_draft"
class Business(BusinessBase):
__tablename__ = "business"
Business has all required (NOT NULL) columns, and BusinessDraft has every field marked with PartialAllowed as nullable.
Example (SQLModel)
from typing import Annotated
from sqlmodel import SQLModel, Field
from partial_tables import PartialSQLModelMixin, PartialAllowed, PartialTable
class BusinessBase(PartialSQLModelMixin, SQLModel):
id: int = Field(primary_key=True, sa_column_kwargs={"autoincrement": True})
business_name: str
city: Annotated[str, PartialAllowed()] = Field()
address: Annotated[str, PartialAllowed()] = Field()
class BusinessDraft(BusinessBase, PartialTable, table=True):
__tablename__ = "business_draft"
class Business(BusinessBase, table=True):
__tablename__ = "business"
License
MIT
Metadata
Release files for partial-tables 0.0.3
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 | |
|---|---|---|---|---|
| partial_tables-0.0.3.tar.gz | 3.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| partial_tables-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / partial_tables-0.0.3.tar.gz
| Download URL | partial_tables-0.0.3.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d14924708a925f9c842451681bbd455b87987826142a4d75ad20649d5df6bc4
|
|
BLAKE2b-256 checksum How to use checksums |
0287dd5ec71b534c4f744a2f24c6215e577ff8b270a6119106c9873e91191444
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 6, 2026.
Transparency logRelease files / partial_tables-0.0.3-py3-none-any.whl
| Download URL | partial_tables-0.0.3-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
127db3e2db4d2da6ee35733a54360205352e479cea36c66532087d51b2a12d2c
|
|
BLAKE2b-256 checksum How to use checksums |
558058e1f763de1d7cee393afaf4c7a34a5f7d87bce6b3987e5dcbe7598a172b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 6, 2026.
Transparency logSecurity for partial-tables 0.0.3
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for partial_tables-0.0.3.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 Jul 6, 2026.
Transparency logA 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.