{"id":26121775,"url":"https://github.com/ametion/dyffi-bus-client","last_synced_at":"2025-04-13T13:05:28.998Z","repository":{"id":279509060,"uuid":"939059914","full_name":"Ametion/Dyffi-Bus-Client","owner":"Ametion","description":"A lightweight Python client library for interacting with Dyffi Bus, enabling seamless message publishing and subscription in an asynchronous pub/sub system.","archived":false,"fork":false,"pushed_at":"2025-03-06T17:21:36.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-04-13T13:05:07.353Z","etag":null,"topics":["dyffi-bus","library","messaging","pubsub","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ametion.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-25T23:33:51.000Z","updated_at":"2025-03-06T17:21:40.000Z","dependencies_parsed_at":"2025-02-25T23:58:21.377Z","dependency_job_id":null,"html_url":"https://github.com/Ametion/Dyffi-Bus-Client","commit_stats":null,"previous_names":["ametion/dyffi-bus-client"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ametion%2FDyffi-Bus-Client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ametion%2FDyffi-Bus-Client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ametion%2FDyffi-Bus-Client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ametion%2FDyffi-Bus-Client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ametion","download_url":"https://codeload.github.com/Ametion/Dyffi-Bus-Client/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717242,"owners_count":21150389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dyffi-bus","library","messaging","pubsub","python"],"created_at":"2025-03-10T14:36:30.723Z","updated_at":"2025-04-13T13:05:28.959Z","avatar_url":"https://github.com/Ametion.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dyffi-Bus-Client\n\n**Dyffi-Bus-Client** is a lightweight Python library for interacting with Dyffi-Bus via HTTP and WebSockets. It abstracts away the details of publishing messages and subscribing to topics, letting you focus on your application logic.\n\n## Installation\n\n\n```bash\npip install dyffi-bus-client\n```\n\n## Usage\n\n### 1. Create a Client\n\n```python\nfrom dyffi_bus_client import DyffiBusClient\n\n# Initialize the client with the base URL of your pub/sub service\nclient = DyffiBusClient(\"http://127.0.0.1:8000\")\n```\n\n### 2. Publish Messages\n\n```python\nmessage_id = client.publish(\"orders\", {\"order_id\": 123, \"customer\": \"Alice\"})\nprint(\"Sent message with ID:\", message_id)\n```\n\n### 2.1. Async Publish Messages (Optional)\n\n```python\nmessage_id = client.publish_async(\"orders\", {\"order_id\": 123, \"customer\": \"Alice\"}) #Its just async version of publish\nprint(\"Sent message with ID:\", message_id)\n```\n\n- **`topic`**: The topic name to publish to.\n- **`payload`**: A dictionary containing the message data.\n\n### 3. Subscribe to a Topic\n\n```python\ndef order_handler(message):\n    print(\"Got Message:\", message)\n    print(\"Order ID:\", message[\"payload\"][\"order_id\"])\n\nclient.subscribe(\"orders\", order_handler, blocking=False)\n```\n\n- **`topic`**: The topic name to subscribe to.\n- **`handler`**: A callback function that receives the message as a Python dictionary.\n- **`blocking=False`**: The subscription runs in a separate thread, so your main program can continue doing other things.  \n  If you set `blocking=True`, the subscription loop will block the current thread until you stop it (e.g., with Ctrl+C).\n\n### 4. Keep the Main Thread Alive (Optional)\n\nIf you used non-blocking subscriptions, you can call:\n\n```python\nclient.listen()\n```\n\nThis starts a simple loop that keeps your script running indefinitely. Press Ctrl+C to stop.\n\n## Full Examples\n\n### Example: Publishing\n\n```python\nfrom dyffi_bus_client import DyffiBusClient\n\nclient = DyffiBusClient(\"http://127.0.0.1:8000\")\n\nmessage_id = client.publish(\"orders\", {\"order_id\": 123, \"customer\": \"Alice\"})\nprint(\"Sent message with ID:\", message_id)\n```\n\n### Example: Subscribing to Multiple Topics\n\n```python\nfrom dyffi_bus_client import DyffiBusClient\n\n\ndef order_handler(message):\n  print(\"Got Message:\", message)\n  print(\"Order ID:\", message[\"payload\"][\"order_id\"])\n\n\ndef topic_handler(message):\n  print(\"Got Message:\", message)\n\n\nclient = DyffiBusClient(\"http://127.0.0.1:8000\")\n\n# Subscribe to 'orders' in a non-blocking thread\nclient.subscribe(\"orders\", order_handler, blocking=False)\n\n# Subscribe to 'myTopic' in a blocking manner\nclient.subscribe(\"myTopic\", topic_handler, blocking=True)\n```\n\nIn this example:\n- We listen to **orders** in a separate thread (non-blocking).\n- We then subscribe to **myTopic** in blocking mode, so the program stays alive until we stop it.\n\n## How It Works\n\n- **`publish(topic, payload)`**  \n  Sends an HTTP POST request to `\u003capi_url\u003e/publish` with the given topic and payload.\n- **`subscribe(topic, handler, blocking=False)`**  \n  Opens a WebSocket connection to `\u003capi_url\u003e/ws/\u003ctopic\u003e` in a separate thread, calling `handler(message)` for every new message.  \n  If `blocking=True`, it runs on the main thread until stopped.\n- **`listen()`**  \n  A simple blocking loop that keeps the main thread alive if you used non-blocking subscriptions.\n\n## License\n\nThis library is provided under the [MIT License](LICENSE). Feel free to open issues or submit pull requests if you encounter any problems or have ideas for new features.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fametion%2Fdyffi-bus-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fametion%2Fdyffi-bus-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fametion%2Fdyffi-bus-client/lists"}