Chancy

A postgres-backed task queue for Python.

MIT License Codecov PyPI Version Supported Versions OS Platforms PostgreSQL Versions

Key Features:

  • Jobs support priorities, retries, timeouts, scheduling, global rate limits, memory limits, global uniqueness, error capture, cancellation, and more

  • Minimal dependencies (only psycopg3 required)

  • Plugins for a dashboard, workflows, cron jobs, and much more

  • Optional transactional enqueueing for atomic job creation

  • asyncio & sync APIs for easy integration with existing codebases

  • 100% open & free - no enterprise or paid features. Checkout the repo on GitHub.

Quick Start

Install Chancy & its CLI:

pip install chancy[cli]

Create a new file called worker.py:

worker.py
from chancy import Chancy, job

@job(queue="default")
def hello_world(*, name: str):
    print(f"Hello, {name}!")

chancy = Chancy("postgresql://localhost/postgres")

Then run the database migrations:

chancy --app worker.chancy misc migrate

Declare a queue:

chancy --app worker.chancy queue declare default --concurrency 10

Push a job:

chancy --app worker.chancy queue push worker.hello_world --kwargs '{"name": "world"}'

Start a worker:

chancy --app worker.chancy worker start

Install Chancy:

pip install chancy

Create a new file called worker.py:

worker.py
 import asyncio
 from chancy import Chancy, Worker, Queue, job

 @job(queue="default")
 def hello_world(*, name: str):
     print(f"Hello, {name}!")

 chancy = Chancy("postgresql://localhost/postgres")

 async def main():
     async with chancy:
         # Run the database migrations
         await chancy.migrate()
         # Declare a queue
         await chancy.declare(Queue("default", concurrency=10))
         # Push a job
         await chancy.push(hello_world.job.with_kwargs(name="World"))
         # Start the worker (ctrl+c to exit)
         async with Worker(chancy) as worker:
             await worker.wait_for_shutdown()

 if __name__ == "__main__":
     asyncio.run(main())

Congratulations! You’ve just run your first Chancy job. Next, explore the How To or plugins.

Dashboard

Chancy comes with a built-in dashboard - no need to run a separate service like Flower.

Jobs page Failed job page Queue page Worker page

Similar Projects

With the addition of modern Postgres features like LISTEN/NOTIFY and SELECT FOR UPDATE...SKIP LOCKED, postgres-backed task queues have become a viable alternative to other task queues built on RabbitMQ or redis like celery. As such the space is exploding with new projects. Here are some of the most popular ones if Chancy doesn’t fit your needs:

Project

Language

Note

celery

Python

The defacto Python task queue

procastinate

Python

oban

Elixir

Inspired many of the features in Chancy

river

Go

neoq

Go

faktory

Go

pg-boss

Node.js

graphile

Node.js

Minion

Perl

Indices and tables