amqp-client-python


Nameamqp-client-python JSON
Version 0.1.13 PyPI version JSON
download
home_pagehttps://github.com/nutes-uepb/amqp-client-python
SummaryPython AMQP Client Library
upload_time2023-07-01 18:12:37
maintainer
docs_urlNone
authorNUTES UEPB
requires_python>=3.7,<4.0
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

[![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] 




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

### 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)_.


[//]: # (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

### 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
)
from amqp_client_python.event import IntegrationEvent, IntegrationEventHandler
config = Config(Options("queue", "rpc_queue", "rpc_exchange"))
eventbus = AsyncEventbusRabbitMQ(config)
# publish
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

publish_event = ExampleEvent(rpc_exchange, ["message"])
eventbus.publish(publish_event, rpc_routing_key, "direct")
# subscribe
class ExampleEventHandler(IntegrationEventHandler):
    def handle(self, body) -> None:
        print(body) # handle messages
await eventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key)
# rpc_publish
response = await eventbus.rpc_client(rpc_exchange, "user.find", ["content_message"])
# provider
async def handle2(*body) -> bytes:
    print(f"body: {body}")
    return b"content"
await eventbus.provide_resource("user.find", handle)
```
</details>

<details><summary>sync usage</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, "direct")
        #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
from amqp_client_python.event import IntegrationEvent, IntegrationEventHandler

config = Config(Options(queue, rpc_queue, rpc_exchange))
eventbus = EventbusWrapperRabbitMQ(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
class ExampleEventHandler(IntegrationEventHandler):
    async def handle(self, body) -> None:
        print(body,"subscribe")

async 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()
# rpc_provider
eventbus.provide_resource(rpc_routing_key+"2", handle).result()
# subscribe
eventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key).result()
count = 0
running = True
while running:
    try:
        count += 1
        # rpc_client call
        eventbus.rpc_client(rpc_exchange, rpc_routing_key+"2", [f"{count}"]).result().decode("utf-8")
        # publish
        eventbus.publish(publish_event, rpc_routing_key, "direct").result()
        #running = False
    except KeyboardInterrupt:
        running=False
    except BaseException as err:
        print("Err:", err)
```
</details>
<br />

### Know Limitations:
#### sync eventbus
```sh
Cannot use rpc call when inside of rpc provider and subscribe handlers
#/obs: works on sync eventbus wrapper
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nutes-uepb/amqp-client-python",
    "name": "amqp-client-python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "packaging,dependency,amqp-client-python",
    "author": "NUTES UEPB",
    "author_email": "dev.seniorsaudemovel@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ec/39/45ac60f691d1c2beb18e386aefbfe7140bedf204972928f9da6decc4fb37/amqp_client_python-0.1.13.tar.gz",
    "platform": null,
    "description": "# AMQP Client Python\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--------\nClient with high level of abstraction for manipulation of messages in the event bus RabbitMQ.\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[//]: # (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\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)\nfrom amqp_client_python.event import IntegrationEvent, IntegrationEventHandler\nconfig = Config(Options(\"queue\", \"rpc_queue\", \"rpc_exchange\"))\neventbus = AsyncEventbusRabbitMQ(config)\n# publish\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\npublish_event = ExampleEvent(rpc_exchange, [\"message\"])\neventbus.publish(publish_event, rpc_routing_key, \"direct\")\n# subscribe\nclass ExampleEventHandler(IntegrationEventHandler):\n    def handle(self, body) -> None:\n        print(body) # handle messages\nawait eventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key)\n# rpc_publish\nresponse = await eventbus.rpc_client(rpc_exchange, \"user.find\", [\"content_message\"])\n# provider\nasync def handle2(*body) -> bytes:\n    print(f\"body: {body}\")\n    return b\"content\"\nawait eventbus.provide_resource(\"user.find\", handle)\n```\n</details>\n\n<details><summary>sync usage</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, \"direct\")\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\nfrom amqp_client_python.event import IntegrationEvent, IntegrationEventHandler\n\nconfig = Config(Options(queue, rpc_queue, rpc_exchange))\neventbus = EventbusWrapperRabbitMQ(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\nclass ExampleEventHandler(IntegrationEventHandler):\n    async def handle(self, body) -> None:\n        print(body,\"subscribe\")\n\nasync def 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()\n# rpc_provider\neventbus.provide_resource(rpc_routing_key+\"2\", handle).result()\n# subscribe\neventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key).result()\ncount = 0\nrunning = True\nwhile running:\n    try:\n        count += 1\n        # rpc_client call\n        eventbus.rpc_client(rpc_exchange, rpc_routing_key+\"2\", [f\"{count}\"]).result().decode(\"utf-8\")\n        # publish\n        eventbus.publish(publish_event, rpc_routing_key, \"direct\").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### Know Limitations:\n#### sync eventbus\n```sh\nCannot use rpc call when inside of rpc provider and subscribe handlers\n#/obs: works on sync eventbus wrapper\n```",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python AMQP Client Library",
    "version": "0.1.13",
    "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": "48bea819904ca86d1b7407c94e334b99c4ea386b3e11bc3f513e5532414df937",
                "md5": "6b8bbad1f8789a46684e74f81df1953a",
                "sha256": "df8cf97aaffc6f7b2c4222727cb7bab5520f72a917b54df112ef00b1501899e5"
            },
            "downloads": -1,
            "filename": "amqp_client_python-0.1.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6b8bbad1f8789a46684e74f81df1953a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 32667,
            "upload_time": "2023-07-01T18:12:34",
            "upload_time_iso_8601": "2023-07-01T18:12:34.740096Z",
            "url": "https://files.pythonhosted.org/packages/48/be/a819904ca86d1b7407c94e334b99c4ea386b3e11bc3f513e5532414df937/amqp_client_python-0.1.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ec3945ac60f691d1c2beb18e386aefbfe7140bedf204972928f9da6decc4fb37",
                "md5": "2d0461988b05201d5067366a0dbd95ab",
                "sha256": "0b9462f284ed495bc606cb249212553a21b3061785369bf6d0d17ce0018705d3"
            },
            "downloads": -1,
            "filename": "amqp_client_python-0.1.13.tar.gz",
            "has_sig": false,
            "md5_digest": "2d0461988b05201d5067366a0dbd95ab",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 22976,
            "upload_time": "2023-07-01T18:12:37",
            "upload_time_iso_8601": "2023-07-01T18:12:37.401556Z",
            "url": "https://files.pythonhosted.org/packages/ec/39/45ac60f691d1c2beb18e386aefbfe7140bedf204972928f9da6decc4fb37/amqp_client_python-0.1.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-01 18:12:37",
    "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.11006s