amqp_helper
Introduction
amqp_helper aims to be a simple Helper library to configure AMQP communication for use with aio-pika
To achieve this goal this Library provides the AMQPConfig class.
This package also provides a log handler to send logs to an AMQP Broker. You can use it via the class AMQPLogHandler
Installation
amqp_helper can be installed in multiple ways. The easiest Solution is to install it with pip.
via pip
python3 -m pip install amqp-helper
from source
git clone https://github.com/bad-microservices/amqp_helper.git
cd amqp_helper
python3 -m pip install .
Example
import asyncio
from amqp_helper import AMQPConfig
from aio_pika import connect_robust
amqp_config = AMQPConfig(username="test",password="testpw",vhost="testvhost")
async def main():
connection = await connect_robust(**amqp_config.aio_pika())
# do some amqp stuff
if __name__ == "__main__":
asyncio.run(main())
Example RPC over AMQP
Server code
The Server code is quite simple
import asyncio
from amqp_helper import AMQPConfig, AMQPService, new_amqp_func
amqp_config = AMQPConfig(username="test",password="testpw",vhost="testvhost")
async def testfunc(throw_value_error = False,throw_key_error = False, throw_exception = False*args, **kwargs):
if throw_value_error:
raise ValueError()
if throw_key_error:
raise KeyError()
if throw_exception:
raise Exception()
return {"result": "sync stuff"}
rpc_fun = new_amqp_func("test1", test1234)
@rpc_fun.exception_handler(ValueError, KeyError)
async def handle_value_error(*args, **kwargs):
retrun "got ValueError or KeyError"
@rpc_fun.exception_handler(Exception)
async def handle_value_error(*args, **kwargs):
return "got Exception"
async def main():
service = await AMQPService().connect(amqp_config)
await service.register_function(rpc_fun)
await service.serve()
# do some amqp stuff
if __name__ == "__main__":
asyncio.run(main())
Client
import asyncio
from amqp_helper import AMQPConfig, AMQPClient
amqp_config = AMQPConfig(username="test",password="testpw",vhost="testvhost")
async def main():
client = await AMQPClient().connect(amqp_config)
print(await client.call(None,"test1"))
if __name__ == "__main__":
asyncio.run(main())
Logging to AMQP
if we want to log to an AMQP Topic we can do it with the following example code.
import logging
from amqp_helper import AMQPLogHandler
log_cfg = AMQPConfig(username="test",password="testpw",vhost="testvhost")
handler = AMQPLogHandler(amqp_config=log_cfg, exchange_name="amqp.topic")
root_logger= logging.getLogger()
root_logger.addHandler(handler)
root_logger.info("test log message")
Metadata
Release files for amqp-helper 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| amqp_helper-0.1.8.tar.gz | 8.8 kB | Without provenance | Details for amqp_helper-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| amqp_helper-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for amqp_helper-0.1.8-py3-none-any.whl |
Total release size: 18.5 kB
Release files / amqp_helper-0.1.8.tar.gz
| Download URL | amqp_helper-0.1.8.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4954cb1ef90dd66324714e91e8ff6525c6860a3c86aea7633b80d5e2cef271ad
|
|
BLAKE2b-256 checksum How to use checksums |
205ec3fa37e625d638aeb8ca5b4f26e41bc4cbfa11517da05f895c487a2c009c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / amqp_helper-0.1.8-py3-none-any.whl
| Download URL | amqp_helper-0.1.8-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58292dc9b820d2a3bf859cfeb251fd24b8f8c51c4d534baba61e73101f9a0483
|
|
BLAKE2b-256 checksum How to use checksums |
5fb76388568fdbfaf3031a1a6d597ff690b1378ae3d977d45a3df657f97793b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for amqp-helper 0.1.8
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.