Skip to main content

larztask

A durable background job/task queue in pure Python. Zero dependencies, no broker.

Register functions as tasks, enqueue jobs (now or scheduled), and run workers that execute them with retries, exponential backoff, priorities, and a dead-letter queue — without Redis, without RabbitMQ, without a single third-party package.

from larztask import TaskQueue

app = TaskQueue("jobs/")              # durable, multi-worker-safe

@app.task(max_retries=3)
def resize_image(path):
    ...                              # raising schedules a retry

resize_image.delay("/tmp/a.jpg")     # enqueue a job
app.work(burst=True)                 # run everything ready, then return

Why

  • Zero dependencies, no broker. No Redis, no message queue, no server to run. A directory is your queue.
  • Durable. Each job is a JSON file, written with fsync. Kill the process and restart — pending jobs are still there.
  • Safely multi-worker. Claiming a job is a single atomic os.rename from queued/ to running/. If two workers race, exactly one wins — no lock files, no double-runs, no coordination service.
  • Real retry semantics. Per-task max_retries with exponential backoff, then a dead-letter queue so failures are visible instead of lost.
  • Scheduling & priorities. Delay a job, run it at a specific time, or bump its priority.
  • Swappable store. MemoryStore for tests and ephemeral work, FileStore for durability — same API.

Install

pip install larztask

Usage

Define tasks

@app.task
def send_welcome(user_id):
    ...

@app.task(max_retries=5, backoff=2.0)     # 2s, 4s, 8s, 16s, 32s
def charge_card(order_id):
    ...

Enqueue

send_welcome.delay(42)                             # as soon as a worker is free
app.enqueue("send_welcome", args=(42,), delay=60)  # in 60 seconds
app.enqueue("charge_card", args=(7,), priority=10) # ahead of lower-priority jobs

Run workers

app.work(burst=True)     # drain all ready jobs, then return  (great for cron)
app.work()               # loop forever, polling; call app.stop() to exit

Run the same script in several processes pointed at the same directory and they share the queue safely. Watch what happens with an event hook:

app.work(on_event=lambda event, job: print(event, job["name"]))
# -> "done send_welcome", "retry charge_card", "dead charge_card", ...

Inspect

app.pending()      # jobs waiting to run
app.counts()       # {"queued": 3, "running": 1, "done": 40, "failed": 0, "dead": 2}
app.store.get(job_id)         # full job record incl. result / error / traceback
app.store.list("dead")        # everything in the dead-letter queue

How a job flows

enqueue ─▶ queued ─▶ (worker claims via atomic rename) ─▶ running
                                                            │
                       success ──────────────────────────▶ done
                       failure, attempts <= max_retries ─▶ queued (after backoff)
                       failure, retries exhausted ───────▶ dead

Scope

larztask is an embedded queue: workers are threads/processes you run, jobs run in-process, and the store is a local directory (or memory). That's the right tool for a huge range of apps — email sending, image processing, webhooks, scheduled cleanups, background computation — without operating a broker. It is not a distributed cross-machine queue; for that you'd point many machines at shared storage or reach for a networked broker.

Tests

python -m unittest discover -s tests -v   # 22 tests (both stores + atomic claim), zero deps

The Larz stack

Pure-Python, zero-dependency building blocks:

  • larz — money-native web framework
  • larzchain — from-scratch PoW blockchain
  • larzmoney — exact, penny-perfect money
  • larzcrypt — pure-Python cryptography toolkit
  • larzdb — crash-safe embedded database
  • larzagent — zero-dep AI agent framework
  • larzchart — data to inline SVG charts
  • larzmark — Markdown + SEO static sites
  • larztask — this library

License

MIT © larz-scripter

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

larztask-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larztask-0.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file larztask-0.1.0.tar.gz.

File metadata

  • Download URL: larztask-0.1.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for larztask-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f386ca4859712108ad9a63b0758f5235f932234c8e5cb0458d7d4b9f053272df
MD5 312ecb3ee60fda2457f86bbb4aa4eb01
BLAKE2b-256 41e7893b3faa82301bfbbceb043a5448f0f3ebe917b33d48f7f714ca3a3a3e10

See more details on using hashes here.

File details

Details for the file larztask-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larztask-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for larztask-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34467f818e95abce851f483057b5a8589608a10e369abb8e103703c4ea912d4d
MD5 7a2447faf8ac6b24bd3ef02e01584724
BLAKE2b-256 9733ded88d258f17c3a35af8ebdbe599a96e0b8e7a3eb8a7d07d942e2e64b981

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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