Skip to main content

simple_module_db

Database layer for the simple_module framework. Provides a per-module Base, an async SQLAlchemy/SQLModel session, standard mixins, and an auto-commit-on-flush listener that removes manual session.commit() calls from service code.

Install

pip install simple_module_db

What it provides

  • create_module_base("<module_name>") — a module-scoped declarative Base with its own MetaData. All modules share the host's single schema, so __tablename__ should be prefixed with the module name (e.g. users_user) to avoid collisions.
  • Per-request RequestSession (get_db) that commits pending writes before the response and rolls back read-only requests.
  • session.on_commit(callback) for synchronous or asynchronous cache refreshes that must only run after a successful request commit.
  • Mixins in simple_module_db.models.mixins: AuditMixin (created_at/updated_at), SoftDeleteMixin (auto-filtered unless stmt.execution_options(include_deleted=True)), MultiTenantMixin, VersionedMixin.
  • DatabaseState container used by the framework to avoid global mutable state.

Usage

# modules/orders/orders/models.py
from simple_module_db import AuditMixin, SoftDeleteMixin, create_module_base
from sqlmodel import Field

Base = create_module_base("orders")


class Order(Base, AuditMixin, SoftDeleteMixin, table=True):
    id: int | None = Field(default=None, primary_key=True)
    customer_id: int = Field(index=True, foreign_key="users_user.id")
    total_cents: int

In a service:

from simple_module_db import RequestSession, get_db

async def create_order(session: RequestSession = Depends(get_db), ...):
    order = Order(customer_id=..., total_cents=...)
    session.add(order)
    await session.flush()   # assigns order.id; commit happens before the response
    session.on_commit(order_cache.refresh)
    return order

Never call session.commit() — the framework handles it.

Depends on

  • simple_module_core, sqlalchemy[asyncio], sqlmodel, alembic, asyncpg, aiosqlite

License

MIT — see LICENSE.

Metadata

Release files for simple-module-db 0.0.51

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

Source distribution (sdist)

Source distribution for simple-module-db 0.0.51
File Size Uploaded Provenance Actions
simple_module_db-0.0.51.tar.gz 183.4 kB With provenance Details for simple_module_db-0.0.51.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-module-db 0.0.51
File Interpreter ABI Platform Actions
simple_module_db-0.0.51-py3-none-any.whl Python 3 none any Details for simple_module_db-0.0.51-py3-none-any.whl

Total release size: 318.8 kB

Release files / simple_module_db-0.0.51.tar.gz

Download URL simple_module_db-0.0.51.tar.gz
Size 183.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b1894df82ca0719fcbe0a66ed2f9c6ae0ec7b344fa775c3387c7a645bb32d72c
BLAKE2b-256 checksum
How to use checksums
47defc6f7df3ea2d27f42566abc0d136c80042711ffdcd2f73cb61491db2b99b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / simple_module_db-0.0.51-py3-none-any.whl

Download URL simple_module_db-0.0.51-py3-none-any.whl
Size 135.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd1475ccb98d8fa2087cabf3d75f3ce4d91c619ff99149164482aaf72b6cd354
BLAKE2b-256 checksum
How to use checksums
33d582da7777910049ae08f659a432d70f77b01c2074c959d944d104b84e6857
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Security for simple-module-db 0.0.51

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 simple_module_db-0.0.51.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 Nov 29, 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.

Release history Release notifications | RSS feed

This release

0.0.51 This release

2 release files Full 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