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/rroblf01/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://rroblf01.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.3.0.tar.gz (211.9 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.3.0-cp310-abi3-win_amd64.whl (167.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

lapinq-1.3.0-cp310-abi3-win32.whl (153.6 kB view details)

Uploaded CPython 3.10+Windows x86

lapinq-1.3.0-cp310-abi3-musllinux_1_2_x86_64.whl (368.5 kB view details)

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

lapinq-1.3.0-cp310-abi3-musllinux_1_2_aarch64.whl (355.3 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

lapinq-1.3.0-cp310-abi3-manylinux_2_28_x86_64.whl (298.3 kB view details)

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

lapinq-1.3.0-cp310-abi3-manylinux_2_28_aarch64.whl (289.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

lapinq-1.3.0-cp310-abi3-macosx_11_0_arm64.whl (265.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

lapinq-1.3.0-cp310-abi3-macosx_10_12_x86_64.whl (268.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for lapinq-1.3.0.tar.gz
Algorithm Hash digest
SHA256 f83368fca0b6a95099a25064376b8a6f555c656a620089c16165c23a3ceaf855
MD5 b973c8d2ee72c11c5b1860198f85e24d
BLAKE2b-256 7d5d07e3e2ca67e71ca532934ce7d6cc877714a504b74fc053bec47b276e955b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: lapinq-1.3.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 167.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.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 743345befdef8b8ae9cd51e4f482273a460ea580f6e4a3838da7381cd5fbea5a
MD5 5954b1cab59da6cbd858ad10a62a0169
BLAKE2b-256 9dd71b38562979a49399292c58403891fd0c17f25af0f8c33e94eb49cdca3577

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: lapinq-1.3.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 153.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.3.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 e4f5fde477cbec17782ff1273707aa4824952b5f6b23e562915d9c5caa6cc041
MD5 e5353e8475b4d0aa3f8835db50fea830
BLAKE2b-256 d0c358af831115819fabf15e36ff50ceb2d250d91a09024998a0ce42856353ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lapinq-1.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6c1bb150ba23cf6d9c42318959ce5ffcde5eb7a7c6fa59bc421b13a065bf2a2a
MD5 2cd7c25349fe145dc6cc7668f095388c
BLAKE2b-256 73678d0f87bc32d78fe1d900565a3bd5e97687dba25bb3b95dcf4a8b106f459d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lapinq-1.3.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 57d1c78c6ebf178c2163562e7ccf9ac002b34d827128a3a06c62d170b3d9639e
MD5 d736d981a07a5109ce16416da3dde503
BLAKE2b-256 8f1b6309bad8753bb723089df4c9ca27efa4303bce803ff8fb018ad146f9e045

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lapinq-1.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4acb5aeca7f4e9efb9ea632f55875ae89c52a30f6a4effe24abbedc977c13ec5
MD5 ed4435e8fdfc768734c2f3c67ac19e39
BLAKE2b-256 8e8932a879d30144abf9a1979d0727e5fe79786d68b95fb0e9de46a48a4a8956

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lapinq-1.3.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6f9c0d89e54162aeb34acc65cd11af38f63a2a4e2d085103dd020c90b48f160d
MD5 8d2bb77673e70996dee2c8ed97abf304
BLAKE2b-256 f651191f35d50f780e1dd2c5b2fb221b52d0a0cde9c66ed76a33e354249d6d65

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lapinq-1.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 259ac4013e029f553e57432f76621d1405d122ef92d2821f87449481db99888c
MD5 839de1884294fb77a21609adb1f58b9c
BLAKE2b-256 c211a02a2ed32226b2a3e10ed63d5924adff480234bfbda5f0c5faebec948898

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lapinq-1.3.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 89ef2366310a6aaa5501c65e45eea20d86c27e42bab9dad47c3b37f26a32762f
MD5 8aa39750b43cd6df45794a171fee4392
BLAKE2b-256 a4c473b6e8494351e0059759b2966dd1cad3337c64fc514ab9c45959d979f1d6

See more details on using hashes here.

Provenance

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