amqp-client-python


Nameamqp-client-python JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/nutes-uepb/amqp-client-python
SummaryPython AMQP Client Library
upload_time2024-10-03 00:02:52
maintainerNone
docs_urlNone
authorNUTES UEPB
requires_python<4.0,>=3.7
licenseApache-2.0
keywords packaging dependency amqp-client-python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AMQP Client Python

Client with high level of abstraction for manipulation of messages in the event bus RabbitMQ.

--------

[![License][license-image]][license-url]
<a href="https://pypi.org/project/amqp-client-python" target="_blank">
    <img src="https://img.shields.io/pypi/v/amqp-client-python?color=%2334D058&label=pypi%20package" alt="Package version">
</a><a href="https://pypi.org/project/amqp-client-python" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/amqp-client-python.svg?color=%2334D058" alt="Supported Python versions">
</a>
[![Downloads](https://static.pepy.tech/personalized-badge/amqp-client-python?period=month&units=international_system&left_color=black&right_color=orange&left_text=PyPI%20downloads%20per%20month)](https://pepy.tech/project/amqp-client-python)
[![Vulnerabilities][known-vulnerabilities-image]][known-vulnerabilities-url]  [![Releases][releases-image]][releases-url] 



---

**Documentation**: <a href="https://nutes-uepb.github.io/amqp-client-python" target="_blank">https://nutes-uepb.github.io/amqp-client-python</a>

**Source Code**: <a href="https://github.com/nutes-uepb/amqp-client-python" target="_blank">https://github.com/nutes-uepb/amqp-client-python</a>

---
### Features:
- Automatic creation and management of queues, exchanges and channels;
- Connection persistence and auto reconnect;
- Support for **direct**, **topic** and **fanout** exchanges;
- Publish;
- Subscribe;
- Support for a Remote procedure call _(RPC)_.


### Table of Compatibility
| version  | compatible with |
| ---- | ---- |
| 0.2.0 | 0.2.0 |
| 0.1.14 | ~0.1.12 |

### Examples:
#### you can use [sync](https://github.com/nutes-uepb/amqp-client-python/blob/develop/amqp_client_python/rabbitmq/eventbus_rabbitmq.py) , [async eventbus](https://github.com/nutes-uepb/amqp-client-python/blob/develop/amqp_client_python/rabbitmq/async_eventbus_rabbitmq.py) and [sync wrapper](https://github.com/nutes-uepb/amqp-client-python/blob/develop/amqp_client_python/rabbitmq/eventbus_wrapper_rabbitmq.py) of async eventbus
<details><summary>async usage </summary>

<br>

```Python
# basic configuration
from amqp_client_python import (
    AsyncEventbusRabbitMQ,
    Config, Options
)
config = Config(Options("queue", "rpc_queue", "rpc_exchange"))
eventbus = AsyncEventbusRabbitMQ(config)
# publish

eventbus.publish("rpc_exchange", "routing.key", "message_content")
# subscribe
async def subscribe_handler(body) -> None:
    print(body, type(body), flush=True) # handle messages
await eventbus.subscribe("rpc_exchange", "routing.key", subscribe_handler)
# rpc_publish
response = await eventbus.rpc_client("rpc_exchange", "user.find", "message_content")
# provider
async def rpc_provider_handler(body) -> bytes:
    print(f"body: {body}")
    return b"content"
await eventbus.provide_resource("user.find", rpc_provider_handler)
```
</details>

<details><summary>sync usage(deprecated)</summary>

```Python
from amqp_client_python import (
    EventbusRabbitMQ,
    Config, Options
)
from amqp_client_python.event import IntegrationEvent, IntegrationEventHandler
from examples.default import queue, rpc_queue, rpc_exchange, rpc_routing_key


class ExampleEvent(IntegrationEvent):
    EVENT_NAME: str = "ExampleEvent"
    ROUTING_KEY: str = rpc_routing_key

    def __init__(self, event_type: str, message = []) -> None:
        super().__init__(self.EVENT_NAME, event_type)
        self.message = message
        self.routing_key = self.ROUTING_KEY


class ExampleEventHandler(IntegrationEventHandler):
    def handle(self, body) -> None:
        print(body,"subscribe")


config = Config(Options(queue, rpc_queue, rpc_exchange))
eventbus = EventbusRabbitMQ(config=config)

class ExampleEvent(IntegrationEvent):
    EVENT_NAME: str = "ExampleEvent"
    def __init__(self, event_type: str, message = []) -> None:
        super().__init__(self.EVENT_NAME, event_type)
        self.message = message

from time import sleep
from random import randint
def handle(*body):
    print(body[0], "rpc_provider")
    return f"{body[0]}".encode("utf-8")

subscribe_event = ExampleEvent(rpc_exchange)
publish_event = ExampleEvent(rpc_exchange, ["message"])
subscribe_event_handle = ExampleEventHandler()
eventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key)
eventbus.provide_resource(rpc_routing_key+"2", handle)
count = 0
running = True
from concurrent.futures import TimeoutError
while running:
    try:
        count += 1
        if str(count) != eventbus.rpc_client(rpc_exchange, rpc_routing_key+"2", [f"{count}"]).decode("utf-8"):
            running = False
        #eventbus.publish(publish_event, rpc_routing_key, "message_content")
        #running = False
    except TimeoutError as err:
        print("timeout!!!: ", str(err))
    except KeyboardInterrupt:
        running=False
    except BaseException as err:
        print("Err:", err)
```
</details>

<details><summary>sync wrapper usage</summary>

```Python
from amqp_client_python import EventbusWrapperRabbitMQ, Config, Options

config = Config(Options("queue", "rpc_queue", "rpc_exchange"))
eventbus = EventbusWrapperRabbitMQ(config=config)

async def subscribe_handler(body) -> None:
    print(f"{body}", type(body), flush=True)

async def rpc_provider_handler(body) -> bytes:
    print(f"handle - {body}", type(body), flush=True)
    return f"{body}".encode("utf-8")

# rpc_provider
eventbus.provide_resource("user.find", rpc_provider_handler).result()
# subscribe
eventbus.subscribe("rpc_exchange", "routing.key", subscribe_handler).result()
count = 0
running = True
while running:
    try:
        count += 1
        # rpc_client call
        eventbus.rpc_client("rpc_exchange", "user.find", count).result().decode("utf-8")
        # publish
        eventbus.publish("rpc_exchange", "routing.key", "message_content").result()
        #running = False
    except KeyboardInterrupt:
        running=False
    except BaseException as err:
        print("Err:", err)
```
</details>
<br />


## Sponsors
The library is provided by NUTES-UEPB.
<br/>
<a href="https://nutes.uepb.edu.br/" target="_blank"><img width="250px" src="https://nutes.uepb.edu.br/wp-content/uploads/2018/11/cropped-logo-Nutes-Final.jpg"></a>

### Know Limitations:
#### basic eventbus
<medium><pre>
When using [**EventbusRabbitMQ**](https://github.com/nutes-uepb/amqp-client-python/blob/master/amqp_client_python/rabbitmq/eventbus_rabbitmq.py#L12) Should not use rpc call inside of rpc provider or subscribe handlers, it may block the ioloop
#/obs: fixed on other kinds of eventbus, will be removed on nexts releases
</pre></medium>



[//]: # (These are reference links used in the body of this note.)
[license-image]: https://img.shields.io/badge/license-Apache%202-blue.svg
[license-url]: https://github.com/nutes-uepb/amqp-client-python/blob/master/LICENSE
[npm-image]: https://img.shields.io/npm/v/amqp-client-python.svg?color=red&logo=npm
[npm-url]: https://npmjs.org/package/amqp-client-python
[downloads-image]: https://img.shields.io/npm/dt/amqp-client-python.svg?logo=npm
[travis-url]: https://travis-ci.org/nutes-uepb/amqp-client-python
[coverage-image]: https://coveralls.io/repos/github/nutes-uepb/amqp-client-python/badge.svg
[coverage-url]: https://coveralls.io/github/nutes-uepb/amqp-client-python?branch=master
[known-vulnerabilities-image]: https://snyk.io/test/github/nutes-uepb/amqp-client-python/badge.svg?targetFile=requirements.txt
[known-vulnerabilities-url]: https://snyk.io/test/github/nutes-uepb/amqp-client-python?targetFile=requirements.txt
[releases-image]: https://img.shields.io/github/release-date/nutes-uepb/amqp-client-python.svg
[releases-url]: https://github.com/nutes-uepb/amqp-client-python/releases
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nutes-uepb/amqp-client-python",
    "name": "amqp-client-python",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.7",
    "maintainer_email": null,
    "keywords": "packaging, dependency, amqp-client-python",
    "author": "NUTES UEPB",
    "author_email": "dev.seniorsaudemovel@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/31/88/d5bc3291c18af79bb2418ab8563aa431ae65b58a96670c284c4a58a20f88/amqp_client_python-0.2.0.tar.gz",
    "platform": null,
    "description": "# AMQP Client Python\n\nClient with high level of abstraction for manipulation of messages in the event bus RabbitMQ.\n\n--------\n\n[![License][license-image]][license-url]\n<a href=\"https://pypi.org/project/amqp-client-python\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/v/amqp-client-python?color=%2334D058&label=pypi%20package\" alt=\"Package version\">\n</a><a href=\"https://pypi.org/project/amqp-client-python\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/pyversions/amqp-client-python.svg?color=%2334D058\" alt=\"Supported Python versions\">\n</a>\n[![Downloads](https://static.pepy.tech/personalized-badge/amqp-client-python?period=month&units=international_system&left_color=black&right_color=orange&left_text=PyPI%20downloads%20per%20month)](https://pepy.tech/project/amqp-client-python)\n[![Vulnerabilities][known-vulnerabilities-image]][known-vulnerabilities-url]  [![Releases][releases-image]][releases-url] \n\n\n\n---\n\n**Documentation**: <a href=\"https://nutes-uepb.github.io/amqp-client-python\" target=\"_blank\">https://nutes-uepb.github.io/amqp-client-python</a>\n\n**Source Code**: <a href=\"https://github.com/nutes-uepb/amqp-client-python\" target=\"_blank\">https://github.com/nutes-uepb/amqp-client-python</a>\n\n---\n### Features:\n- Automatic creation and management of queues, exchanges and channels;\n- Connection persistence and auto reconnect;\n- Support for **direct**, **topic** and **fanout** exchanges;\n- Publish;\n- Subscribe;\n- Support for a Remote procedure call _(RPC)_.\n\n\n### Table of Compatibility\n| version  | compatible with |\n| ---- | ---- |\n| 0.2.0 | 0.2.0 |\n| 0.1.14 | ~0.1.12 |\n\n### Examples:\n#### you can use [sync](https://github.com/nutes-uepb/amqp-client-python/blob/develop/amqp_client_python/rabbitmq/eventbus_rabbitmq.py) , [async eventbus](https://github.com/nutes-uepb/amqp-client-python/blob/develop/amqp_client_python/rabbitmq/async_eventbus_rabbitmq.py) and [sync wrapper](https://github.com/nutes-uepb/amqp-client-python/blob/develop/amqp_client_python/rabbitmq/eventbus_wrapper_rabbitmq.py) of async eventbus\n<details><summary>async usage </summary>\n\n<br>\n\n```Python\n# basic configuration\nfrom amqp_client_python import (\n    AsyncEventbusRabbitMQ,\n    Config, Options\n)\nconfig = Config(Options(\"queue\", \"rpc_queue\", \"rpc_exchange\"))\neventbus = AsyncEventbusRabbitMQ(config)\n# publish\n\neventbus.publish(\"rpc_exchange\", \"routing.key\", \"message_content\")\n# subscribe\nasync def subscribe_handler(body) -> None:\n    print(body, type(body), flush=True) # handle messages\nawait eventbus.subscribe(\"rpc_exchange\", \"routing.key\", subscribe_handler)\n# rpc_publish\nresponse = await eventbus.rpc_client(\"rpc_exchange\", \"user.find\", \"message_content\")\n# provider\nasync def rpc_provider_handler(body) -> bytes:\n    print(f\"body: {body}\")\n    return b\"content\"\nawait eventbus.provide_resource(\"user.find\", rpc_provider_handler)\n```\n</details>\n\n<details><summary>sync usage(deprecated)</summary>\n\n```Python\nfrom amqp_client_python import (\n    EventbusRabbitMQ,\n    Config, Options\n)\nfrom amqp_client_python.event import IntegrationEvent, IntegrationEventHandler\nfrom examples.default import queue, rpc_queue, rpc_exchange, rpc_routing_key\n\n\nclass ExampleEvent(IntegrationEvent):\n    EVENT_NAME: str = \"ExampleEvent\"\n    ROUTING_KEY: str = rpc_routing_key\n\n    def __init__(self, event_type: str, message = []) -> None:\n        super().__init__(self.EVENT_NAME, event_type)\n        self.message = message\n        self.routing_key = self.ROUTING_KEY\n\n\nclass ExampleEventHandler(IntegrationEventHandler):\n    def handle(self, body) -> None:\n        print(body,\"subscribe\")\n\n\nconfig = Config(Options(queue, rpc_queue, rpc_exchange))\neventbus = EventbusRabbitMQ(config=config)\n\nclass ExampleEvent(IntegrationEvent):\n    EVENT_NAME: str = \"ExampleEvent\"\n    def __init__(self, event_type: str, message = []) -> None:\n        super().__init__(self.EVENT_NAME, event_type)\n        self.message = message\n\nfrom time import sleep\nfrom random import randint\ndef handle(*body):\n    print(body[0], \"rpc_provider\")\n    return f\"{body[0]}\".encode(\"utf-8\")\n\nsubscribe_event = ExampleEvent(rpc_exchange)\npublish_event = ExampleEvent(rpc_exchange, [\"message\"])\nsubscribe_event_handle = ExampleEventHandler()\neventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key)\neventbus.provide_resource(rpc_routing_key+\"2\", handle)\ncount = 0\nrunning = True\nfrom concurrent.futures import TimeoutError\nwhile running:\n    try:\n        count += 1\n        if str(count) != eventbus.rpc_client(rpc_exchange, rpc_routing_key+\"2\", [f\"{count}\"]).decode(\"utf-8\"):\n            running = False\n        #eventbus.publish(publish_event, rpc_routing_key, \"message_content\")\n        #running = False\n    except TimeoutError as err:\n        print(\"timeout!!!: \", str(err))\n    except KeyboardInterrupt:\n        running=False\n    except BaseException as err:\n        print(\"Err:\", err)\n```\n</details>\n\n<details><summary>sync wrapper usage</summary>\n\n```Python\nfrom amqp_client_python import EventbusWrapperRabbitMQ, Config, Options\n\nconfig = Config(Options(\"queue\", \"rpc_queue\", \"rpc_exchange\"))\neventbus = EventbusWrapperRabbitMQ(config=config)\n\nasync def subscribe_handler(body) -> None:\n    print(f\"{body}\", type(body), flush=True)\n\nasync def rpc_provider_handler(body) -> bytes:\n    print(f\"handle - {body}\", type(body), flush=True)\n    return f\"{body}\".encode(\"utf-8\")\n\n# rpc_provider\neventbus.provide_resource(\"user.find\", rpc_provider_handler).result()\n# subscribe\neventbus.subscribe(\"rpc_exchange\", \"routing.key\", subscribe_handler).result()\ncount = 0\nrunning = True\nwhile running:\n    try:\n        count += 1\n        # rpc_client call\n        eventbus.rpc_client(\"rpc_exchange\", \"user.find\", count).result().decode(\"utf-8\")\n        # publish\n        eventbus.publish(\"rpc_exchange\", \"routing.key\", \"message_content\").result()\n        #running = False\n    except KeyboardInterrupt:\n        running=False\n    except BaseException as err:\n        print(\"Err:\", err)\n```\n</details>\n<br />\n\n\n## Sponsors\nThe library is provided by NUTES-UEPB.\n<br/>\n<a href=\"https://nutes.uepb.edu.br/\" target=\"_blank\"><img width=\"250px\" src=\"https://nutes.uepb.edu.br/wp-content/uploads/2018/11/cropped-logo-Nutes-Final.jpg\"></a>\n\n### Know Limitations:\n#### basic eventbus\n<medium><pre>\nWhen using [**EventbusRabbitMQ**](https://github.com/nutes-uepb/amqp-client-python/blob/master/amqp_client_python/rabbitmq/eventbus_rabbitmq.py#L12) Should not use rpc call inside of rpc provider or subscribe handlers, it may block the ioloop\n#/obs: fixed on other kinds of eventbus, will be removed on nexts releases\n</pre></medium>\n\n\n\n[//]: # (These are reference links used in the body of this note.)\n[license-image]: https://img.shields.io/badge/license-Apache%202-blue.svg\n[license-url]: https://github.com/nutes-uepb/amqp-client-python/blob/master/LICENSE\n[npm-image]: https://img.shields.io/npm/v/amqp-client-python.svg?color=red&logo=npm\n[npm-url]: https://npmjs.org/package/amqp-client-python\n[downloads-image]: https://img.shields.io/npm/dt/amqp-client-python.svg?logo=npm\n[travis-url]: https://travis-ci.org/nutes-uepb/amqp-client-python\n[coverage-image]: https://coveralls.io/repos/github/nutes-uepb/amqp-client-python/badge.svg\n[coverage-url]: https://coveralls.io/github/nutes-uepb/amqp-client-python?branch=master\n[known-vulnerabilities-image]: https://snyk.io/test/github/nutes-uepb/amqp-client-python/badge.svg?targetFile=requirements.txt\n[known-vulnerabilities-url]: https://snyk.io/test/github/nutes-uepb/amqp-client-python?targetFile=requirements.txt\n[releases-image]: https://img.shields.io/github/release-date/nutes-uepb/amqp-client-python.svg\n[releases-url]: https://github.com/nutes-uepb/amqp-client-python/releases",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python AMQP Client Library",
    "version": "0.2.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/nutes-uepb/amqp-client-python/issues",
        "Homepage": "https://github.com/nutes-uepb/amqp-client-python",
        "Repository": "https://github.com/nutes-uepb/amqp-client-python"
    },
    "split_keywords": [
        "packaging",
        " dependency",
        " amqp-client-python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "abfb785ae7924d1321455c1733a62c402465252afde1f32de5f606c281306bb7",
                "md5": "ea643c720bd32041590d827c014e540a",
                "sha256": "d3f9407899b399d4aae3d617e0d1fca7a6f3385dba643dfd433dfb62419eeac4"
            },
            "downloads": -1,
            "filename": "amqp_client_python-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea643c720bd32041590d827c014e540a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 40157,
            "upload_time": "2024-10-03T00:02:50",
            "upload_time_iso_8601": "2024-10-03T00:02:50.847947Z",
            "url": "https://files.pythonhosted.org/packages/ab/fb/785ae7924d1321455c1733a62c402465252afde1f32de5f606c281306bb7/amqp_client_python-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3188d5bc3291c18af79bb2418ab8563aa431ae65b58a96670c284c4a58a20f88",
                "md5": "a08f8ac5594052a2906b76a688581a29",
                "sha256": "da48b1046037facf56cd39354181159f3be9d47a49ac93408eadda99b3ff800f"
            },
            "downloads": -1,
            "filename": "amqp_client_python-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a08f8ac5594052a2906b76a688581a29",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 28359,
            "upload_time": "2024-10-03T00:02:52",
            "upload_time_iso_8601": "2024-10-03T00:02:52.553659Z",
            "url": "https://files.pythonhosted.org/packages/31/88/d5bc3291c18af79bb2418ab8563aa431ae65b58a96670c284c4a58a20f88/amqp_client_python-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-03 00:02:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nutes-uepb",
    "github_project": "amqp-client-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "amqp-client-python"
}
        
Elapsed time: 0.32927s