RabbitMQ throw & catch messages
Project description
throw-catch
Small RabbitMQ helpers for publishing, receiving, and clearing JSON messages with minimal setup.
throw-catch is designed for lightweight workflows where you want to drop structured messages into a queue, fetch them back in tests or background jobs, and keep the API surface tiny.
Highlights
- Simple
throw,catch, andclearfunctions. - JSON serialization via
orjson. - Optional message tags for selective reads.
- Per-message TTL support in minutes.
- Works with Python
3.11+. - Managed with
uv.
Installation
uv add throw-catch
Quick Start
import os
from throw_catch import catch, clear, throw
amqp_uri = os.getenv("AMQP_URI")
throw(payload={"hello": "world"}, uri=amqp_uri)
messages = catch(uri=amqp_uri)
print(messages)
clear(uri=amqp_uri)
Usage
Publish messages
from throw_catch import throw
throw(
payload={"event": "user.created", "user_id": 42},
uri="amqp://guest:guest@localhost:5672/",
)
throw(
payload={"event": "invoice.ready"},
tag="billing",
routing_key="events.billing",
ttl=30,
uri="amqp://guest:guest@localhost:5672/",
)
Notes:
payloadmust be a non-empty dictionary.ttlis in minutes.ttl=0publishes without expiration.
Receive messages
from throw_catch import catch
messages = catch(
uri="amqp://guest:guest@localhost:5672/",
queue="events.billing",
tag="billing",
count=10,
)
catch returns a list of decoded message dictionaries and acknowledges only the messages it actually returns.
Clear a queue
from throw_catch import clear
clear(
uri="amqp://guest:guest@localhost:5672/",
queue="events.billing",
)
API
throw(payload, tag=None, uri=None, routing_key="throw_catch", ttl=180)
Publishes a message to the target queue.
catch(tag=None, uri=None, queue="throw_catch", count=1)
Reads up to count messages from the queue and returns them as a list.
clear(uri=None, queue="throw_catch")
Deletes the target queue.
Development
Install dependencies:
uv sync --dev
Run tests:
uv run pytest
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
Built Distribution
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 throw_catch-0.3.0.tar.gz.
File metadata
- Download URL: throw_catch-0.3.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab0e2eeacfaf71d9204a6996938aa3c56275f069a05677cb6c91240b12b9cac6
|
|
| MD5 |
58f61c76494cb039cd9b7fc5729caf71
|
|
| BLAKE2b-256 |
201a70d50a237b32927990414a481c03a9b623f93c49051aef697c07d43e06ad
|
File details
Details for the file throw_catch-0.3.0-py3-none-any.whl.
File metadata
- Download URL: throw_catch-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4914fa2433105687dcc2ff94033bbcafd227b5b0fb8c0879dabb1c6dcf59848
|
|
| MD5 |
264d7dc44a76726efd2879a205e1e0e7
|
|
| BLAKE2b-256 |
92957cc11c54d3d82c903fed83317d9bda6efd94dabadeaf890d4dde73a69529
|