Skip to main content

awa-pg

Python bindings for awa, a Postgres-native background job queue. Same engine, same SQL, same defaults as the Rust core; native-speed dispatch via PyO3.

pip install awa-pg

Quick start

import asyncio
import os
from dataclasses import dataclass

from awa import AsyncClient


@dataclass
class SendEmail:
    to: str
    subject: str


async def main():
    client = AsyncClient(os.environ["DATABASE_URL"])

    @client.task(SendEmail, queue="email")
    async def send_email(job):
        print(f"sending to {job.args.to}: {job.args.subject}")

    await client.start([("email", 4)])  # 4 workers on the email queue

    await client.insert(
        SendEmail(to="ada@example.com", subject="hello"),
        queue="email",
    )

    await asyncio.sleep(1)
    await client.shutdown()

asyncio.run(main())

A synchronous worker model is also available via awa.Client for codebases that aren't async-first.

For application tables, keep using your existing database library. The awa.bridge helpers insert jobs through asyncpg, psycopg3, SQLAlchemy, or Django connections so app rows and jobs can commit in the same transaction.

What you get

  • Transactional enqueue — enqueue inside the same Postgres transaction as your application's writes, using your existing connection/session.
  • Vacuum-aware storage — append-only ready entries plus a partitioned receipt ring keep dead-tuple pressure bounded under sustained load. See ADR-019 and ADR-023.
  • COPY ingestionenqueue_many_copy streams directly into queue storage for high-volume Python producers. insert_many_copy remains the compatibility insert surface for canonical-storage and adapter-style callers. If workers use queue_storage_queue_stripe_count > 1, pass the same value to enqueue_many_copy.
  • Partitioned queuesPartitionedQueue maps one hot logical queue to several physical queues so workers can drain independent streams without changing Awa's durability model.
  • Crash-safe execution — heartbeat-based lease tracking; jobs whose workers vanish are rescued automatically.
  • Per-queue policy — priorities, priority aging, weighted concurrency, rate limits, deadlines, retry/backoff, cron, dead-letter queue.
  • Durable batch operations — preview, submit, monitor, and cancel async operator mutations such as reprioritizing queued jobs or moving a backlog to another queue.
  • Progress tracking — handlers can write structured progress that survives across retries.
  • Web UI (optional)pip install 'awa-pg[ui]' pulls in the awa-cli wheel, which ships the dashboard binary. Then python -m awa serve (or awa serve directly) runs a live queue inspector, DLQ triage console, and retry controls on http://127.0.0.1:3000. The default awa-pg install stays small for workers and producers that don't need the dashboard.

Migrations

python -m awa --database-url "$DATABASE_URL" migrate

Fresh installs go straight to the queue-storage engine on first migrate. Existing 0.5.x installations should follow docs/upgrade-0.5-to-0.6.md for the staged transition.

Durable batch operations

Batch operations are for operator-scale mutations. They preview a filtered set, persist a control-plane record, and let the maintenance leader apply the mutation in small chunks. Python exposes the generic envelope and helpers for the first two operation kinds:

preview = await client.preview_set_priority(
    1,
    filter={"queue": "default", "state": "available"},
)

operation = await client.set_priority(
    1,
    filter={"queue": "default"},
    submitted_by="ops@example.com",
)

operation = await client.move_queue(
    "escalations",
    priority=1,
    filter={"tag": "incident-123"},
)

active = await client.list_batch_operations(state="running")
await client.cancel_batch_operation(operation["id"])

awa.Client has the same methods for synchronous scripts. Batch operations affect queued available and scheduled jobs; running, waiting, terminal, and DLQ rows keep their current attempt state.

Partitioned FIFO and ordering keys

Queues default to strict FIFO per (queue, priority). Operators can raise awa.queue_meta.enqueue_shards on a contended queue to trade strict FIFO for throughput; the contract then becomes partitioned FIFO — strict order within each shard, no ordering promised across shards. This is the same kind of decision as choosing SQS Standard over SQS FIFO, raising Kafka partition count, or using Pub/Sub ordering keys.

If your producer enqueues related jobs that must execute in order — events for one customer, steps in one workflow, writes for one account — pass ordering_key so all jobs sharing that key land on the same shard:

await client.insert(
    UpdateCustomer(customer_id=42, payload=...),
    queue="customer-updates",
    ordering_key=b"customer-42",
)

The key can be bytes or str (encoded UTF-8). Two enqueues with the same key always pick the same shard regardless of which producer process or batch they came from. At enqueue_shards = 1 (the default) the key is ignored. See docs/adr/025-sharded-enqueue-heads.md for the full contract.

Partitioned queues

A logical queue is the workload name your application thinks in, such as customer-updates. A physical queue is the queue name stored in Postgres and claimed by workers. Most workloads use one physical queue. For a very hot workload where partitioned ordering is acceptable, use PartitionedQueue to spread one logical queue over several physical queues:

queue = awa.PartitionedQueue("customer-updates", 4)

@client.task(UpdateCustomer, queue=queue.physical_queues[0])
async def update_customer(job):
    ...

await client.start(queue.queue_configs(max_workers_per_partition=16))

await client.insert(
    UpdateCustomer(customer_id=42, payload=...),
    **queue.route_by_key("customer-42"),
)

Register the handler once and pass explicit partition configs to start(). Python handlers are dispatched by job kind; the queue name on @client.task gives start() a declared queue to validate.

route_by_key() returns queue and ordering_key, so jobs for the same key pick the same physical queue and keep per-key FIFO. route_by_index() returns a round-robin queue for workloads that do not need per-key ordering. The worker queue_configs() helper is explicit about max_workers_per_partition because each physical queue is configured independently; pass global_max_workers to start() if you need a logical fleet-wide cap.

insert_many_copy() and enqueue_many_copy() accept per-job opts, so a mixed-partition batch can still use one COPY call:

await client.enqueue_many_copy(
    jobs,
    opts=[queue.route_by_key(job.customer_id) for job in jobs],
)

Documentation

License

Dual-licensed under MIT or Apache-2.0, at your option.

Release files for awa-pg 0.6.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for awa-pg 0.6.8
File
awa_pg-0.6.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
awa_pg-0.6.8-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
awa_pg-0.6.8-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
awa_pg-0.6.8-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 45.8 MB

Release files / awa_pg-0.6.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL awa_pg-0.6.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 11.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e3c98170a07a17c5b39847f9d689cc025841f1e3c45effb5250387a03955cbd4
BLAKE2b-256 checksum
How to use checksums
3556528e23d1697a27ef2666aec7c8fdb86f04930ca78aa03701a7fdb3804f97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / awa_pg-0.6.8-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL awa_pg-0.6.8-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 12.5 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
cd807b927a5c3006ab270e1da136063e2c737813e1f40df25a5f3dde938210ed
BLAKE2b-256 checksum
How to use checksums
4121dd9987edd46d454f9d96e71b114357d038ee9bebcc9f3504f3ffc3f873bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / awa_pg-0.6.8-cp310-abi3-macosx_11_0_arm64.whl

Download URL awa_pg-0.6.8-cp310-abi3-macosx_11_0_arm64.whl
Size 10.7 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e948661c7682bc4769924d6bbe3981ed6ceaf7da9e7bd30857b0463faf776487
BLAKE2b-256 checksum
How to use checksums
0709945b03118f8608e778f44465ff0588e3a64c555f06c1c56b912b6f150339
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / awa_pg-0.6.8-cp310-abi3-macosx_10_12_x86_64.whl

Download URL awa_pg-0.6.8-cp310-abi3-macosx_10_12_x86_64.whl
Size 11.0 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0dfadf4d1fc00e1b5525ff51c959ea0a4ae421087aea4f560704e2fe1bd23274
BLAKE2b-256 checksum
How to use checksums
b03f470e5687abe6f58a873439f6aee8c5d563f148e77b1c117f3fa15238086f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release history Release notifications | RSS feed

0.6.9

4 release files

This release

0.6.8 This release

4 release files

0.6.7

4 release files

0.6.6

4 release files

0.6.5

4 release files

0.6.4

4 release files

0.6.3

4 release files

0.6.2

4 release files

0.6.1

4 release files

0.6.0

4 release files

0.5.7

4 release files

0.5.6

4 release files

0.5.5

4 release files

0.5.3

4 release files

0.5.2

4 release files

0.5.1

4 release files

0.5.0

4 release files

0.4.1

4 release files

0.4.0

4 release files

0.3.0

4 release files

0.2.1

4 release files

0.2.0

4 release files

0.1.6

4 release files

0.1.4

3 release 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