An embedded, crash-resilient, persistent queue engine for Python.
Project description
LMDB-QUEUE
Persistent, crash-safe job queue for Python. No broker. No daemon. Just disk.
Jobs survive process restarts. Workers run as threads or separate processes on the same machine. Powered by LMDB, a memory-mapped database that writes atomically and recovers instantly after a crash.
Install
pip install lmdb-queue
uv add lmdb-queue
Usage
Basic
from equeue import Queue
with Queue("./myqueue") as q:
q.put({"task": "send_email", "to": "user@example.com"})
record = q.get(timeout=5.0)
try:
send(record.payload)
record.ack() # job done
except Exception:
record.nack() # re-queue, or mark FAILED after too many retries
Context manager (auto ack / nack)
with Queue("./myqueue") as q:
with q.processing(timeout=5.0) as record:
process(record.payload)
# ack() on success, nack() on any exception
Async
from equeue import AsyncQueue
async with AsyncQueue("./myqueue") as q:
await q.put({"task": "resize_image"})
async with q.processing() as record:
await handle(record.payload)
The Record
get() returns a Record. Completion always goes through the record, never through a bare job ID. This prevents one worker from accidentally finishing a job held by another.
| Field | Meaning |
|---|---|
payload |
Job data passed to put() |
job_id |
Stable integer ID, useful for logs |
retries |
How many times this job was nacked |
enqueued_at |
Unix timestamp from put() |
Configuration
q = Queue(
"./myqueue",
lease_time=30.0, # seconds before an idle job can be re-queued
max_retries=3, # nacks before FAILED (0 = one attempt only)
map_size=2**30, # LMDB virtual size in bytes (default 1 GiB)
sync=False, # True = safer, slower (fsync every write)
do_recover=True, # background thread re-queues expired jobs
recover_interval=15.0,
do_vacuum=True, # background thread removes old DONE jobs
vacuum_interval=300.0,
)
Statistics
q.stats()
# {
# "pending": 4, # waiting for a worker
# "running": 1, # claimed by a worker
# "done": 120, # finished successfully
# "failed": 2, # exceeded retry limit
# "total": 127, # ever enqueued; never decreases
# }
Job lifecycle
PENDING --> RUNNING --> DONE --> (vacuumed)
|
+--> PENDING nack() with retries left, or lease expired
|
+--> FAILED nack() with no retries left (kept on disk)
Exceptions
| Exception | When |
|---|---|
QueueEmpty |
get(timeout=...) found no job in time |
QueueClosed |
Operation on a closed queue |
QueueCorrupted |
Wrong claim token, double ack, or broken disk state |
Notes
- At-least-once delivery. A job can run more than once if a worker crashes or its lease expires. Make handlers idempotent.
- Payload types. Values must be msgpack-serializable: dicts, lists, strings, numbers, bytes,
None. map_sizeis not disk usage. It is virtual address space. Disk grows as data is written.- Not a distributed broker. EQueue is for one machine. It does not replace Redis or Kafka.
Docs
uv run pytest # all tests
uv run pytest -m contract # RFC contract tests only
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lmdb_queue-0.1.1.tar.gz.
File metadata
- Download URL: lmdb_queue-0.1.1.tar.gz
- Upload date:
- Size: 116.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccc9fb70bf05a93abad396b95018aa99ab9ff692e3147d5ef2c632ac1c44df62
|
|
| MD5 |
3d5094b25f446390ed3bca80c6f28ed4
|
|
| BLAKE2b-256 |
f9950098926ce06df1bf7d8b2b73e26c92a9270b482be5b03b26765b49ae24eb
|
Provenance
The following attestation bundles were made for lmdb_queue-0.1.1.tar.gz:
Publisher:
publish.yml on PabloSanchi/equeue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmdb_queue-0.1.1.tar.gz -
Subject digest:
ccc9fb70bf05a93abad396b95018aa99ab9ff692e3147d5ef2c632ac1c44df62 - Sigstore transparency entry: 2105149452
- Sigstore integration time:
-
Permalink:
PabloSanchi/equeue@cfac5cbda02517e4db8e8870f1e572af63fa100a -
Branch / Tag:
refs/heads/master - Owner: https://github.com/PabloSanchi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cfac5cbda02517e4db8e8870f1e572af63fa100a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file lmdb_queue-0.1.1-py3-none-any.whl.
File metadata
- Download URL: lmdb_queue-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50dfcb3bd170dfbe4788430ad3b88f40cb8ef6a72431b15f0e1ff724547a7233
|
|
| MD5 |
1ab21de794a01e50ba88bb7df8157f5a
|
|
| BLAKE2b-256 |
902fc065137fb7e1740a54a8bf54962bf322aadc0b31f34efca2a383b7ccae53
|
Provenance
The following attestation bundles were made for lmdb_queue-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on PabloSanchi/equeue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lmdb_queue-0.1.1-py3-none-any.whl -
Subject digest:
50dfcb3bd170dfbe4788430ad3b88f40cb8ef6a72431b15f0e1ff724547a7233 - Sigstore transparency entry: 2105149698
- Sigstore integration time:
-
Permalink:
PabloSanchi/equeue@cfac5cbda02517e4db8e8870f1e572af63fa100a -
Branch / Tag:
refs/heads/master - Owner: https://github.com/PabloSanchi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cfac5cbda02517e4db8e8870f1e572af63fa100a -
Trigger Event:
workflow_dispatch
-
Statement type: