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) 8.510 8.904 0.96 n/a; n/a
imagededup Compare 1,000 images / 999,000 directed pairs 150.199 106.599 1.41 n/a; n/a
imagededup Build + compare 1,000 images / 999,000 directed pairs 139.493 133.968 1.04 n/a; n/a
superset SQL Lab: 3,000 queries / 10,000 rows 150.445 165.700 0.91 42.066s / 1550; 49.179s / 1615
saleor Export: 1,000 x 256 products + 1,000 emails 109.182 138.540 0.79 24.518s / 495; 37.793s / 757
paperless_ngx OCR: 200 scans, archive and index 105.615 60.843 1.74 44.666s / 90; 7.350s / 22
posthog 2FA: 5,000 requests / 10,000 tasks 210.518 330.952 0.64 0.276s / 16; 102.777s / 4451
sentry Email: 2,000 requests / 4,000 deliveries 60.303 60.157 1.00 0.054s / 16; 1.094s / 172

Run: github-37987827539-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.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 dbworker 0.1.0
File Size Uploaded
dbworker-0.1.0.tar.gz 32.5 kB Details

Built distribution (wheel)

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

Total release size: 42.9 kB

Release files / dbworker-0.1.0.tar.gz

Download URL dbworker-0.1.0.tar.gz
Size 32.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6876ff5c0e51ae541f7288ef39ee88fb584919d8a7a04ca30e298eb68f1dc93e
BLAKE2b-256 checksum
How to use checksums
f008ff93ea078eb907032474d6bba6457be9a7de7e682618e9bcf8d5956310d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

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

Download URL dbworker-0.1.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f918720763bc92325f477b11ce324434571857fda4be763773f137fd11920034
BLAKE2b-256 checksum
How to use checksums
a85e967f31832437e0f0912024e1287ef00da29a67d4707b5e8c7491db06a168
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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