Skip to main content

A lightweight task queue with PostgreSQL backend

Project description

Lapinq ๐Ÿ‡

A lightweight task queue with PostgreSQL backend โ€” replacing Celery + RabbitMQ with a single container.

CI PyPI Python License


Why Lapinq?

Celery + RabbitMQ is powerful but heavyweight for many projects. Lapinq replaces both with a single container:

  • No separate broker โ€” PostgreSQL handles both storage and queueing
  • No separate worker daemon โ€” Python or Rust worker built in
  • Real-time dashboard โ€” Monitor queues and tasks out of the box
  • Configurable concurrency โ€” Control exactly how many tasks run simultaneously

Quick Start

from lapinq import TaskQueue

tasks = TaskQueue(server_url="http://localhost:8001", queue_name="video")

@tasks.task(name="transcode_video")
def transcode_video(video_id: int, codec: str):
    print(f"Transcoding video {video_id} to {codec}")

# Enqueue the task โ€” runs on the worker
# Use .queue() for sync clients or .aqueue() for async clients
ref = transcode_video.queue(video_id=1, codec="h264")
print(f"Task ID: {ref.task_id}")

# Optional: wait for result (polling)
result = ref.wait(timeout=30)
print(result["status"], result.get("result"))

Installation

pip install lapinq

Or from source:

git clone https://github.com/ricardorobles/lapinq.git
cd lapinq
pip install maturin
maturin develop

Usage

1. Start PostgreSQL

docker run -d --name lapinq-pg \
  -e POSTGRES_USER=lapinq \
  -e POSTGRES_PASSWORD=secret \
  -e POSTGRES_DB=lapinq \
  -p 5432:5432 \
  postgres:16-alpine

2. Start the server

lapinq server --host 0.0.0.0 --port 8001

3. Start a worker

# Python worker (development)
lapinq worker --concurrency 4

# Or Rust worker (production, ~20x faster polling)
lapinq-worker --database-url postgresql://lapinq:secret@localhost:5432/lapinq --concurrency 4

4. Open the dashboard

Visit http://localhost:8001/dashboard to monitor queues and tasks in real time.

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     HTTP      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     SQL      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Web App     โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ   โ”‚  Lapinq Server   โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ   โ”‚ PostgreSQL โ”‚
โ”‚  (FastAPI/   โ”‚               โ”‚  Server          โ”‚              โ”‚            โ”‚
โ”‚   Django)    โ”‚               โ”‚  (Starlette)     โ”‚              โ”‚  Tasks     โ”‚
โ”‚              โ”‚               โ”‚  + Dashboard     โ”‚              โ”‚            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ””โ”€โ”€โ”€โ”€โ”€โ–ฒโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                         โ”‚                              โ”‚
                                         โ”‚  spawns                      โ”‚ polls
                                         โ–ผ                              โ”‚
                                โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”‚
                                โ”‚  Worker           โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚
                                โ”‚  (Rust or Python) โ”‚  FOR UPDATE
                                โ”‚                   โ”‚  SKIP LOCKED
                                โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Features

Feature Status
@tasks.task() decorator API โœ…
PostgreSQL queue storage โœ…
REST API for task management โœ…
Real-time HTMX dashboard โœ…
Python native worker โœ…
Rust worker (high performance) โœ…
Configurable concurrency โœ…
Task timeout โœ…
Task cancellation & requeue โœ…
Multiple queues โœ…
CORS support โœ…
Graceful shutdown โœ…
Docker Compose โœ…
GitHub Actions CI/CD โœ…
MkDocs documentation โœ…
Task metadata / tags โœ…
Task progress tracking โœ…
Batch enqueue โœ…
Configurable retry policies โœ…
Default TTL per queue โœ…
Webhook callbacks โœ…
TaskRef โ€” awaitable results โœ…
Manual retry (RetryError exception) โœ…
CLI task management โœ…
Cron-based periodic scheduler โœ…

Documentation

Full documentation is available at https://ricardorobles.github.io/lapinq

Docker

docker compose up -d

This starts:

  • PostgreSQL โ€” database engine
  • Server โ€” lapinq REST API + dashboard
  • Rust Worker โ€” high-performance task executor (requires --profile rust)

Development

uv sync
uv run maturin develop
uv run pytest

Roadmap

โœ… Complete

  • @tasks.task() decorator API, PostgreSQL queue, REST API, WebSocket dashboard
  • Python + Rust workers, configurable concurrency, task timeout, cancellation
  • Multiple queues, CORS, graceful shutdown, Docker Compose, CI/CD
  • Task history, retries with backoff, stale task reaper, scheduled tasks
  • Priority queues, async client, Dead Letter Queue, worker heartbeat
  • Auth (API key), rate limiting, Prometheus metrics, structured logging
  • PyPI package, i18n docs (EN + ES), TTL support, Rust executor (PyO3)
  • Task metadata / tags, progress tracking, batch enqueue
  • Configurable retry policies, default TTL per queue, webhook callbacks
  • TaskRef (awaitable results), manual Retry exception
  • CLI task management (lapinq task list|get|cancel|requeue)
  • Cron-based periodic scheduler (lapinq server --scheduler)
  • Schema migrations, CHANGELOG.md, abi3 wheels

๐ŸŸข Future

  • Task chaining / workflows (chain, group, chord)
  • Distributed rate limiting (Redis-backed)
  • OpenTelemetry tracing
  • Pre/post task middleware hooks
  • CONTRIBUTING.md โ€” development guide
  • Code coverage in CI โ€” upload to Codecov

Database Schema

All queue state lives in a single table lapinq_tasks:

Column Type Default Description
id UUID gen_random_uuid() Primary key
queue_name TEXT โ€” Queue this task belongs to
task_name TEXT โ€” Name of the function to call
module_path TEXT โ€” Python module to import
args JSONB [] Positional arguments
kwargs JSONB {} Keyword arguments
status TEXT pending One of: pending, running, completed, failed, cancelled, expired
result TEXT โ€” Serialized return value (completed tasks)
error TEXT โ€” Error message (failed tasks)
attempts INT 0 Number of execution attempts
max_retries INT 3 Max retries before marking as failed
priority INT 0 Higher values claim first
metadata JSONB {} Arbitrary key-value pairs
progress INT 0 Progress percentage (0โ€“100)
retry_delay FLOAT โ€” Fixed delay between retries (seconds)
retry_backoff BOOLEAN true Exponential backoff
webhook_url TEXT โ€” URL called on completion/failure
created_at TIMESTAMPTZ now() Creation timestamp
scheduled_at TIMESTAMPTZ now() Earliest allowed claim time
started_at TIMESTAMPTZ โ€” When a worker claimed the task
completed_at TIMESTAMPTZ โ€” When the task finished (completed or failed)
last_heartbeat TIMESTAMPTZ โ€” Worker periodic heartbeat
worker_id TEXT โ€” Which worker claimed the task

Key indexes:

  • idx_tasks_status โ€” filtering by status + created_at order
  • idx_tasks_scheduled โ€” efficient pending-task polling (WHERE status = 'pending')
  • idx_tasks_pending_priority โ€” priority-aware claiming

Environment Variables

| Variable | Default | Used by | Purpose | |---|---|---|---|---| | DATABASE_URL | postgresql://localhost:5432/lapinq | server, worker, execute | PostgreSQL connection string | | LAPINQ_API_KEY | (none โ€” auth disabled) | server | Enables X-API-Key auth middleware | | LAPINQ_RATE_LIMIT | 0 (disabled) | server | Max requests per minute per IP | | LAPINQ_MAX_PAYLOAD_SIZE | 102400 (100KB) | server | Max JSON payload size for enqueue | | LAPINQ_POOL_SIZE | 10 | server, worker | PostgreSQL connection pool size | | LAPINQ_HEARTBEAT_INTERVAL | 15.0 | worker | Seconds between worker heartbeats | | LAPINQ_CORS_ORIGINS | * | server | Comma-separated allowed CORS origins | | LAPINQ_JSON_LOG | 0 (text logging) | server, worker, execute | Set to 1 for structured JSON | | LAPINQ_LOG_LEVEL | INFO | server, worker, execute | Log level override |

Task Lifecycle

enqueue โ”€โ”€โ–บ pending โ”€โ”€โ–บ running โ”€โ”€โ–บ completed
                โ”‚                     โ”‚
                โ”‚                     โ”œโ”€โ”€ result captured
                โ”‚                     โ””โ”€โ”€ status = 'completed'
                โ”‚
                โ””โ”€โ”€ (scheduled_at in future)
                        โ””โ”€โ”€ claimed after scheduled_at

running โ”€โ”€โ–บ fail (attempts < max_retries)
                โ””โ”€โ”€ pending (scheduled with backoff)

running โ”€โ”€โ–บ fail (attempts >= max_retries)
                โ””โ”€โ”€ failed (stored with error)

running โ”€โ”€โ–บ worker crash / timeout
                โ””โ”€โ”€ pending (recovered by stale-task reaper)

failed โ”€โ”€โ–บ requeue
                โ””โ”€โ”€ pending (reset attempts = 0)

Retry backoff schedule: 10s, 30s, 60s, 300s, 600s (cap at 600s).


License

MIT

Project details


Download files

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

Source Distribution

lapinq-1.2.0.tar.gz (196.3 kB view details)

Uploaded Source

Built Distributions

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

lapinq-1.2.0-cp310-abi3-win_amd64.whl (158.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

lapinq-1.2.0-cp310-abi3-win32.whl (144.5 kB view details)

Uploaded CPython 3.10+Windows x86

lapinq-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl (359.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

lapinq-1.2.0-cp310-abi3-musllinux_1_2_aarch64.whl (346.3 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

lapinq-1.2.0-cp310-abi3-manylinux_2_28_x86_64.whl (289.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

lapinq-1.2.0-cp310-abi3-manylinux_2_28_aarch64.whl (280.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

lapinq-1.2.0-cp310-abi3-macosx_11_0_arm64.whl (256.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

lapinq-1.2.0-cp310-abi3-macosx_10_12_x86_64.whl (259.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file lapinq-1.2.0.tar.gz.

File metadata

  • Download URL: lapinq-1.2.0.tar.gz
  • Upload date:
  • Size: 196.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lapinq-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a211dd28eafd167e1b0fb5fe8014be20ab70584e8cb40fb049b6321b1e7f2db0
MD5 08a483c66e1cdd72e3cd1766d31e341b
BLAKE2b-256 3b0c7e573ed076642dacc1354b89a9f1069ad711bbd2aa0f110e6efa42cb413f

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0.tar.gz:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lapinq-1.2.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: lapinq-1.2.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 158.0 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lapinq-1.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 84e801f993d247e09b35311d17903e8e0cf1ad6700d43862ad5cf753ece31a37
MD5 8104d5a09a5d9aa4bff9aab8ec898ed1
BLAKE2b-256 3c08f7acc1eb80456044ab9a546bf83ab87d9fedf1d267f24bfac7be7ea9e402

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0-cp310-abi3-win_amd64.whl:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lapinq-1.2.0-cp310-abi3-win32.whl.

File metadata

  • Download URL: lapinq-1.2.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 144.5 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lapinq-1.2.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 f6fcf2cb9b31f02975ce6d9d621cb98a51a36b970383e539acadcd5b1c4c8006
MD5 2104a64b95b27b8bb188e0b55eba4ed2
BLAKE2b-256 7e0a36af3f85600c64715f34c039b8d3508004843452d8764598b49a9161be5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0-cp310-abi3-win32.whl:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lapinq-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lapinq-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 47f4726b4a63685f5aa31ced6e5cf6ecb9e16a65bcf06b00423795f15f243df0
MD5 b58cc1f5aa2d27c758e393e9c4d1c562
BLAKE2b-256 495a76b13545bab2b268e08d25c86f9791d074e66be7f48135f441d6c968c66d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lapinq-1.2.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for lapinq-1.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 94eca2fec4d921979de44ddafb83875dac99c6336cafb84863cd7ac597e1f396
MD5 ecadb1ce530785236d82b8fc94d8a80d
BLAKE2b-256 4f68005b0a2b6928aaecac37cf2e4937b3da35f0f3240fb3259257158c7b8cf3

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0-cp310-abi3-musllinux_1_2_aarch64.whl:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lapinq-1.2.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lapinq-1.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 24b609b90a4095796be12d8915c9d87c7d375966ab266873cafa9cc79b8494df
MD5 02a8f9ba677cf2f796c4845eedf650e7
BLAKE2b-256 bcf5198ee439094511b0686da9d13ba8c04bb143b004d5edeb0d93ebaea0a53f

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lapinq-1.2.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for lapinq-1.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9e373cd10702eebe116efb983d8e37cc623126f928290239e9ef1411cc54692a
MD5 7279520d6ee65dfa7d8372bb4fe38e8b
BLAKE2b-256 766cf20cad20583d7dd6d31ab23647284d75def059c8d964c866c720a3db429a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lapinq-1.2.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lapinq-1.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c44d0c977399249017f670bb204360f7853c6215261ef103e1daaba565233b2
MD5 6de77da4fdd8277997f8a19e2507529b
BLAKE2b-256 3d3fdd422e764df179a1add267b06dcf68a1456afdf19e7aa02628ab81f4b035

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lapinq-1.2.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for lapinq-1.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c54a5f2fc8178202e0d91b2531c8b1d2db729b0ebc643ee3f35e8de3c67aa072
MD5 71c5a2058d47fbc9fcf818cba38fa972
BLAKE2b-256 9838605ce13dc991241c115afa11a33fde5966e5355f75c514500c4112147131

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.2.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: publish.yml on rroblf01/lapinq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page