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="procesar_video")
def procesar_video(video_id: int, codec: str):
    print(f"Processing video {video_id} with {codec}")

# Enqueue the task โ€” runs on the worker
procesar_video(video_id=1, codec="h264")

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 โœ…
Multiple queues โœ…
CORS support โœ…
Graceful shutdown โœ…
Docker Compose โœ…
GitHub Actions CI/CD โœ…
MkDocs documentation โœ…

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 โ€” v1.0.0

โœ… Complete (v0.1.0)

  • @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)

๐Ÿ”ต Phase 1 โ€” Production hardening (current)

  • Rust worker: graceful shutdown โ€” signal handlers for SIGTERM/SIGINT
  • Rust worker: connection pool โ€” replace single Client with deadpool-postgres
  • Rust worker: heartbeat โ€” periodic last_heartbeat updates
  • Rust worker: integration tests โ€” test against real PostgreSQL
  • WebSocket error logging โ€” replace bare except: pass with logging
  • Request body validation โ€” catch malformed JSON in enqueue endpoint
  • CI: Python version matrix โ€” test 3.10โ€“3.14 on Linux, 3.14 on Win/Mac
  • CI: security scanning โ€” add bandit / trivy
  • Configurable constants โ€” MAX_PAYLOAD_SIZE, HEARTBEAT_INTERVAL, pool size via env
  • CORS configurable โ€” allow_origins via env var

๐ŸŸก Phase 2 โ€” v1.0.0 release

  • Schema migrations โ€” versioned migration strategy
  • CHANGELOG.md โ€” release history
  • CONTRIBUTING.md โ€” development guide
  • abi3 wheels โ€” single wheel for all Python 3.x versions
  • Code coverage in CI โ€” upload to Codecov
  • Validated query params โ€” safe limit parsing
  • Rust error types โ€” Box<dyn Error> over raw String
  • Tag v1.0.0 โ€” publish to PyPI + GitHub Pages

๐ŸŸข Future (post v1.0.0)

  • Recurring/cron tasks
  • Task chaining / workflows (chain, group, chord)
  • Distributed rate limiting (Redis-backed)
  • OpenTelemetry tracing
  • AsyncResult / task result retrieval
  • Pre/post task middleware hooks

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
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
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.0.0.tar.gz (183.0 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.0.0-cp310-abi3-win_amd64.whl (151.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

lapinq-1.0.0-cp310-abi3-win32.whl (138.6 kB view details)

Uploaded CPython 3.10+Windows x86

lapinq-1.0.0-cp310-abi3-musllinux_1_2_x86_64.whl (352.9 kB view details)

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

lapinq-1.0.0-cp310-abi3-musllinux_1_2_aarch64.whl (339.9 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

lapinq-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl (280.3 kB view details)

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

lapinq-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl (274.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

lapinq-1.0.0-cp310-abi3-macosx_11_0_arm64.whl (250.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

lapinq-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl (253.4 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for lapinq-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ab1b1fdb62b21a019a556ac8182ea73e025d09650de0fc06b077194f1e740173
MD5 734406a72bf65c98df067228f7f39938
BLAKE2b-256 5a29a53ccd625b21592ef17f2180b62885f8084a614c0a56bc1c6781e5b41dd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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.0.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: lapinq-1.0.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 151.9 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.0.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bd3cf0f6018b1d520fcd2bd722a3d9f84fdbc3745d9cb15a3be9447faeff9508
MD5 07cd2a75e559c2af4ff43ba0ea5ddfda
BLAKE2b-256 25073bbf03035cd571a2c74610bd9c9cfe3872e5b3284afc0379549b48a030e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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.0.0-cp310-abi3-win32.whl.

File metadata

  • Download URL: lapinq-1.0.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 138.6 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.0.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 7d4b7102509ea5bf481cda5ba6d6f6b8baca6afe55cb28e699094e96229eb105
MD5 ffc0e1f59de8a769821d38b6658a4a36
BLAKE2b-256 e274bc07f0320231939b1295f272afd81c3ce08870e7bb4a1a510fd755c21ad0

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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.0.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lapinq-1.0.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eb30f151b15df768b06881598672c695f4359ac3ac9674ae5e71b64a31fa17bc
MD5 5993952f7297170e7c3223493f753134
BLAKE2b-256 4cf226d2c4f12fac7105d51628d1bf26710c292ae431b2b1c48f41b7b72bbdb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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.0.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for lapinq-1.0.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 8c0c8f7ebc3647c1437f408cdccb6d1855f57e7a0c69cecc2d229c0a9f3d295b
MD5 6ab61df1b27bfb9849cf922dc82c4aa8
BLAKE2b-256 d0b17c5bd96d8f7745689be1db320307290ceef56069962994a10d3f6e459543

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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.0.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lapinq-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 22708aea32b1670c04ac99b7b76c5ccdc988d6536e36b56d302624fca077ae50
MD5 69d73840bf2e1d9c31d82b61fa8015b7
BLAKE2b-256 eb247f0d702607f22eed3e3951bf26114493dee4da8c22bcfcd229b6ba0d6464

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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.0.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for lapinq-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ecb7322528e40a79c04b45c87bdfee82ff77651d86e27fb0d0e94b0dda75ddec
MD5 9b6d8acd00feff21ba4c23a05df5b74f
BLAKE2b-256 27cb724ae45b651bfcf98fe26404bf9f77477104ac6f1fc85dc1f5ee7e4314dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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.0.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lapinq-1.0.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be3bad949035f3e15c1fc6c03392d6e6651478c6df7031bdf51e98a44982289d
MD5 b1d1ea2489c7c64667cde201e7b8af8a
BLAKE2b-256 ac6c52d30915a4aa4d50e002652c13c30ac18d5b086804c4b30900aa1ecc9f5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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.0.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for lapinq-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6e2d10b9b855b77400abfdb1eea3fee1ad92eabad3fae63db02d41427bd0e05f
MD5 1a2b8bca7a132423f98590eaaf1ab408
BLAKE2b-256 20d0e82db88ac4eb6b62794fc8e21d0fcc99617943cade23263d785ef80a90cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for lapinq-1.0.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