Skip to main content

dbworker

Your database rows are already the queue.

A portable, single-script background worker for SQLAlchemy. No broker, no enqueue, no duplicate job model.

Celery / Huey / Graphile Worker:
    event → job → worker

dbworker:
    row → worker

Requires Python 3.12+. Install into your application:

poetry add dbworker

Usage

Register a handler for an existing SQLAlchemy model. DBWorker discovers eligible rows, runs the handler in a child process, and commits its database changes with the execution status.

from sqlalchemy import select
from sqlalchemy.orm import Session
from dbworker import Coordinator, Finished

coordinator = Coordinator(session_factory, database_url=database_url)

@coordinator.transactional_worker(
    name="process",
    source=YourModel,
    eligible=lambda: (
        select(YourModel)
        .where(YourModel.your_bool_property.is_(True))
        .order_by(YourModel.id)
    ),
    concurrency=4,
)
def process(source: YourModel, session: Session) -> Finished:
    # Apply your application logic using the supplied session.
    return Finished()

if __name__ == "__main__":
    coordinator.create_worker_tables()
    coordinator.start()

YourModel, session_factory, and database_url come from your application. eligible selects which rows can be claimed and in what order. It is optional: omitting it selects from the whole model. DBWorker automatically excludes completed, failed, and actively claimed work. Return Finished() when processing is complete; no enqueue call is needed.

See the Usage Instructions for eligibility queries, incremental processing, service startup and shutdown, status tracking, dependencies, failure handling, and configuration.

Examples

License

MIT © 2026 Ziyang Song.

Benchmark Results

Median wall time in seconds; bold marks the faster backend. Each experiment runs in a fresh Docker container on its own GitHub-hosted Ubuntu VM. Fixed profile: 8 producers, a 60-second scheduled submission window and 8 total execution slots; image hash building uses one native bulk import. Three repetitions per backend. Actual schedule delays and backlog are recorded in JSON; this is one load point, not a maximum-capacity search.

Experiment Workload Celery wall (s) DBWorker wall (s) C / D Task P95 / peak outstanding (C; D)
imagededup Build 1,000 image hashes (one bulk import) 6.459 6.005 1.08 n/a; n/a
imagededup Compare 1,000 images / 999,000 directed pairs 81.712 77.167 1.06 n/a; n/a
imagededup Build + compare 1,000 images / 999,000 directed pairs 92.450 88.584 1.04 n/a; n/a
superset SQL Lab: 3,000 queries / 10,000 rows 153.735 168.862 0.91 42.354s / 1462; 48.725s / 1511
saleor Export: 1,000 x 256 products + 1,000 emails 137.652 167.635 0.82 39.572s / 630; 54.428s / 812
paperless_ngx OCR: 200 scans, archive and index 142.059 81.849 1.74 78.973s / 118; 57.944s / 61
posthog 2FA: 5,000 requests / 10,000 tasks 184.240 164.843 1.12 0.161s / 14; 0.179s / 30
sentry Email: 2,000 requests / 4,000 deliveries 60.314 60.336 1.00 0.057s / 16; 0.479s / 149

Run: github-38401468222-1. Details and scope · JSON results. Scoped application workloads; Sentry uses historical 24.1.0. Wall time includes the fixed submission window, so a ratio near 1 does not prove equal processing capacity. Task P95 starts at publication; peak outstanding counts already published tasks. Ratios above 1 favor DBWorker; no cross-project average is computed.

Metadata

Release files for dbworker 0.1.3

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

Source distribution (sdist)

Source distribution for dbworker 0.1.3
File Size Uploaded Provenance
dbworker-0.1.3.tar.gz 33.5 kB With provenance Details

Built distribution (wheel)

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

Total release size: 45.2 kB

Release files / dbworker-0.1.3.tar.gz

Download URL dbworker-0.1.3.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b0b2c605994e20db30480d81f4171dc2605702162e01ed2b37285214d19f7f45
BLAKE2b-256 checksum
How to use checksums
3d0a3211e09f0953ab704e59596f0bdb20b7ad9994516ecfd67f77f9e8c0737b
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 Oct 23, 2026.

Transparency log

Release files / dbworker-0.1.3-py3-none-any.whl

Download URL dbworker-0.1.3-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a747fda5b24eaeceaa51c6e33b9c7fb1345e7f6a1d3f12fe03626f98725d8cf8
BLAKE2b-256 checksum
How to use checksums
f7f019777407c9a79e91e5bcef7b2f82c84f21e82ceabc8339420ec53aa2b079
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 Oct 23, 2026.

Transparency log

Security for dbworker 0.1.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.

Select from 2 files

Attestation for dbworker-0.1.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 Oct 23, 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