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) 5.781 6.066 0.95 n/a; n/a
imagededup Compare 1,000 images / 999,000 directed pairs 82.087 77.527 1.06 n/a; n/a
imagededup Build + compare 1,000 images / 999,000 directed pairs 91.669 90.453 1.01 n/a; n/a
superset SQL Lab: 3,000 queries / 10,000 rows 130.809 146.255 0.89 34.381s / 1384; 41.335s / 1494
saleor Export: 1,000 x 256 products + 1,000 emails 132.599 160.993 0.82 35.885s / 606; 48.863s / 792
paperless_ngx OCR: 200 scans, archive and index 134.649 75.436 1.78 71.852s / 114; 47.910s / 51
posthog 2FA: 5,000 requests / 10,000 tasks 115.049 110.402 1.04 0.109s / 15; 0.594s / 65
sentry Email: 2,000 requests / 4,000 deliveries 60.263 60.300 1.00 0.033s / 20; 0.147s / 26

Run: github-38214437264-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.2

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.2
File Size Uploaded
dbworker-0.1.2.tar.gz 33.5 kB Details

Built distribution (wheel)

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

Total release size: 45.0 kB

Release files / dbworker-0.1.2.tar.gz

Download URL dbworker-0.1.2.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7e789af31c5037c62d1818231d665a2f569a0fd910166125206c95ee9f863bc4
BLAKE2b-256 checksum
How to use checksums
cfc4ea989b79ed0ca9f65b78159f18bfc8524c90d093f979700658ceeaace6b7
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 13, 2026.

Transparency log

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

Download URL dbworker-0.1.2-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9d413f6a6266eaec4e7db3b833ef4d9f6f4ae6592cee5bdfbadcac7a1f299c6
BLAKE2b-256 checksum
How to use checksums
56ed0c83fab79b9be8e5d6185839db4016fc3bdfa635ee77eef80460e0092d94
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 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

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