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 ingestion —
enqueue_many_copystreams directly into queue storage for high-volume Python producers.insert_many_copyremains the compatibility insert surface for canonical-storage and adapter-style callers. If workers usequeue_storage_queue_stripe_count > 1, pass the same value toenqueue_many_copy. - Partitioned queues —
PartitionedQueuemaps 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 theawa-cliwheel, which ships the dashboard binary. Thenpython -m awa serve(orawa servedirectly) runs a live queue inspector, DLQ triage console, and retry controls onhttp://127.0.0.1:3000. The defaultawa-pginstall 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
- Getting started (Python)
- Configuration
- Dead Letter Queue
- Architecture
- Cross-system benchmark comparison
License
Dual-licensed under MIT or Apache-2.0, at your option.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file awa_pg-0.6.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: awa_pg-0.6.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 10.9 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7098d0ec6a4506916418bec2298582d98ba8d3a01ef698dee913d04960b24e32
|
|
| MD5 |
27a6cc4b966f3b427210abd694840718
|
|
| BLAKE2b-256 |
b361ef9f7e5375986bf9512c5f9ba12292313aede8be3ac65cc9d27ec4ed744f
|
Provenance
The following attestation bundles were made for awa_pg-0.6.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on hardbyte/awa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
awa_pg-0.6.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
7098d0ec6a4506916418bec2298582d98ba8d3a01ef698dee913d04960b24e32 - Sigstore transparency entry: 2171543473
- Sigstore integration time:
-
Permalink:
hardbyte/awa@864c2e8bc0f5985bdabd630405b25d69216b3a4a -
Branch / Tag:
refs/tags/v0.6.3 - Owner: https://github.com/hardbyte
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8bc0f5985bdabd630405b25d69216b3a4a -
Trigger Event:
push
-
Statement type:
File details
Details for the file awa_pg-0.6.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: awa_pg-0.6.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 11.3 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
407a5f1338082e3f892f8fa1cffffc9329fe36acf4d104baec0cd4101f9696fb
|
|
| MD5 |
89857e870ba80c2f7aca0316eee6bd39
|
|
| BLAKE2b-256 |
8b6cc1fe86b6d11268adb5dd1fdead3ddb80f17aaae73e7dfaf4999d3054798a
|
Provenance
The following attestation bundles were made for awa_pg-0.6.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on hardbyte/awa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
awa_pg-0.6.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
407a5f1338082e3f892f8fa1cffffc9329fe36acf4d104baec0cd4101f9696fb - Sigstore transparency entry: 2171543485
- Sigstore integration time:
-
Permalink:
hardbyte/awa@864c2e8bc0f5985bdabd630405b25d69216b3a4a -
Branch / Tag:
refs/tags/v0.6.3 - Owner: https://github.com/hardbyte
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8bc0f5985bdabd630405b25d69216b3a4a -
Trigger Event:
push
-
Statement type:
File details
Details for the file awa_pg-0.6.3-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: awa_pg-0.6.3-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 10.2 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d071d6bd14d11ce1ce0b10a03eecfafbd6b66750092fe8f5520a1b5bf1e92aae
|
|
| MD5 |
08b48fa16e5d5908ef67db514784286b
|
|
| BLAKE2b-256 |
ff531877aac413ab29cdb86ab058652eb161cedc15d14b6e63b9b0d7d47d54b0
|
Provenance
The following attestation bundles were made for awa_pg-0.6.3-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on hardbyte/awa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
awa_pg-0.6.3-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
d071d6bd14d11ce1ce0b10a03eecfafbd6b66750092fe8f5520a1b5bf1e92aae - Sigstore transparency entry: 2171543467
- Sigstore integration time:
-
Permalink:
hardbyte/awa@864c2e8bc0f5985bdabd630405b25d69216b3a4a -
Branch / Tag:
refs/tags/v0.6.3 - Owner: https://github.com/hardbyte
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8bc0f5985bdabd630405b25d69216b3a4a -
Trigger Event:
push
-
Statement type:
File details
Details for the file awa_pg-0.6.3-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: awa_pg-0.6.3-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 10.7 MB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5f445b38bf3bc43956f0917d7623f3d41db91b197f22861a824d56639d64edc
|
|
| MD5 |
81ab46a5fc893c5fbca6da60b2869b20
|
|
| BLAKE2b-256 |
ef7f7cc97bff16f0dfe9f401767d115c2d4cd1a3c3d26b13b73b64bdc67e297e
|
Provenance
The following attestation bundles were made for awa_pg-0.6.3-cp310-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on hardbyte/awa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
awa_pg-0.6.3-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
c5f445b38bf3bc43956f0917d7623f3d41db91b197f22861a824d56639d64edc - Sigstore transparency entry: 2171543477
- Sigstore integration time:
-
Permalink:
hardbyte/awa@864c2e8bc0f5985bdabd630405b25d69216b3a4a -
Branch / Tag:
refs/tags/v0.6.3 - Owner: https://github.com/hardbyte
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@864c2e8bc0f5985bdabd630405b25d69216b3a4a -
Trigger Event:
push
-
Statement type: