Skip to main content

Portable SQLAlchemy repository kit: sync and async CRUD, statement builders, sort/pagination, and SQL helpers.

Project description

sqlphilosophy

Portable SQLAlchemy repository kit for typed CRUD, fluent statement building, sort/pagination, and Core SQL helpers — with explicit sync and async session APIs.

PyPI sqlphilosophy
GitHub SignalSafeSoftware/sqlphilosophy
Import sqlphilosophy (no root reexports — use explicit submodules below)

Developed in the DeliveryPlus monorepo under libs/sqlphilosophy; this tree is the publishable package source.

Install

pip install sqlphilosophy

Async ORM (AsyncSession) also needs greenlet:

pip install sqlphilosophy[async]

Requires Python 3.12+ and SQLAlchemy 2.x.

Package layout

Module Contents
sqlphilosophy.types Portable typing aliases (RowMapping, PrimaryKey, SqlFilter, …)
sqlphilosophy.sql Row mapping helpers, partial updates, Core table helpers, filter builders
sqlphilosophy.sorting ListQuery, SortConfig, SortSpec, pagination/sort resolution
sqlphilosophy.sync Sync BaseRepository, StatementQueryBuilder, RepositoryFactory protocol
sqlphilosophy.aio Async AsyncBaseRepository, AsyncStatementQueryBuilder, AsyncRepositoryFactory
sqlphilosophy.audit Optional SQLAlchemy audit listeners and timestamp mixins

Sync usage

from sqlalchemy.orm import Session

from sqlphilosophy.sorting import ListQuery, SortConfig, SortSpec
from sqlphilosophy.sql import partial_update_model, row_int
from sqlphilosophy.sync.protocols import RepositoryFactory
from sqlphilosophy.sync.repository import BaseRepository
from sqlphilosophy.sync.query import SqlAlchemyStatementBuilder

# Without a factory — statement() returns SqlAlchemyStatementBuilder directly
repo = BaseRepository(User, session)
rows = repo.statement().where(User.active.is_(True)).mappings().all()

# With a factory — statement() and for_repo() delegate to the factory
repo = BaseRepository(User, session, factory)
page = repo.statement().fetch_page(ListQuery.from_page(page=1, size=20))
other = repo.for_repo(OrderRepository)

Async usage

from sqlalchemy.ext.asyncio import AsyncSession

from sqlphilosophy.aio.repository import AsyncBaseRepository

repo = AsyncBaseRepository(User, session)
rows = await repo.statement().where(User.active.is_(True)).mappings().all()

Audit mixins

from sqlphilosophy.audit.context import audit_context
from sqlphilosophy.audit.listener import configure_audit_listeners
from sqlphilosophy.audit.model import TimestampModel

configure_audit_listeners()

with audit_context(actor_id=42):
    session.add(MyModel(name="example"))
    session.flush()

Development

python -m pip install -e ".[dev]"
python -m pytest
python -m build
python -m twine check dist/*

Releasing

See RELEASING.md for GitHub + PyPI trusted publishing.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlphilosophy-0.1.0.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlphilosophy-0.1.0-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file sqlphilosophy-0.1.0.tar.gz.

File metadata

  • Download URL: sqlphilosophy-0.1.0.tar.gz
  • Upload date:
  • Size: 33.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for sqlphilosophy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c82b230ad188265399ed57aea383c7274394084d10fa7771eeff2291f13a3948
MD5 50b54106f8be8935c83df54c4ce416d2
BLAKE2b-256 9d0027dbdb4f44a010a1b7114bf5497f599e278f81116bbcef8fbf65105afc21

See more details on using hashes here.

File details

Details for the file sqlphilosophy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sqlphilosophy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for sqlphilosophy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fea03f10f39fefb0c57d4d25b12052b7b61dd4bdd4b937f982495dfda4460825
MD5 b074b1b5b632e9cbaf2681b65af29891
BLAKE2b-256 59cbc781fc9971c3181c1ece4001fd63c9928f1c77ffce5d0ac8e48b02a682c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page