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
- Image deduplication: independent FastAPI and worker services, artifact building, paged comparisons, and worker dependencies.
- Redis + Celery equivalent.
- Benchmarks with structured JSON results.
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.
| Experiment | Scenario | Celery (s) | DBWorker (s) | Celery / DBWorker |
|---|---|---|---|---|
| imagededup | build | 4.885 | 5.939 | 0.82 |
| imagededup | comparison | 78.031 | 74.414 | 1.05 |
| imagededup | mixed | 85.559 | 86.142 | 0.99 |
| superset | sql_lab_group_by | 2.045 | 2.070 | 0.99 |
| saleor | product_csv_export | 1.912 | 2.272 | 0.84 |
| paperless_ngx | scanned_image_ingestion | 40.368 | 40.143 | 1.01 |
| posthog | pre_rendered_notification_smtp | 2.006 | 1.511 | 1.33 |
| sentry | historical_smtp_email | 157.003 | 150.927 | 1.04 |
Run: github-37351143262-1. Details and scope · JSON results.
Scoped application workloads; Sentry uses historical 24.1.0. Ratios above 1 favor DBWorker; no cross-project average is computed.
Metadata
Release files for dbworker 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dbworker-0.0.7.tar.gz | 31.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dbworker-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.6 kB
Release files / dbworker-0.0.7.tar.gz
| Download URL | dbworker-0.0.7.tar.gz |
|---|---|
| Size | 31.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bd07ea7eb9183295079509c625881b8b25e65bd721088c15a2a2d4bedc42a2e
|
|
BLAKE2b-256 checksum How to use checksums |
bc72a7c89d5c1fab7a349583273ae7edb0631668fa8a016887d3fe5b34dc401b
|
| 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 5, 2026.
Transparency logRelease files / dbworker-0.0.7-py3-none-any.whl
| Download URL | dbworker-0.0.7-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f43b5de0944b82013cdcc03739054e2a8a31ff6c866795bfe75e1b66fa7c2fe1
|
|
BLAKE2b-256 checksum How to use checksums |
6a0c1e40dd1092c32115a90b5a122355f7c4e32f03bf7224089603e66e478239
|
| 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 5, 2026.
Transparency log