# Hivemind Bus Client
Python client library for [hivemind-core](https://github.com/JarbasHiveMind/HiveMind-core)
## Install
```bash
pip install hivemind_bus_client
```
## Usage
via [hivemind-http-protocol](https://github.com/JarbasHiveMind/hivemind-http-protocol)
```python
from hivemind_bus_client.http_client import HiveMindHTTPClient
# not passing key etc so it uses identity file
client = HiveMindHTTPClient(host="http://localhost", port=5679)
client.connect() # establish a secure end-to-end encrypted connection
```
via [hivemind-websocket-protocol](https://github.com/JarbasHiveMind/hivemind-websocket-protocol)
```python
from hivemind_bus_client.client import HiveMessageBusClient
# not passing key etc so it uses identity file
client = HiveMessageBusClient(host="ws://localhost", port=5678)
client.connect() # establish a secure end-to-end encrypted connection
```
### Example: Simple Chat
```python
import threading
from ovos_bus_client.message import Message
from hivemind_bus_client.message import HiveMessage, HiveMessageType
from hivemind_bus_client.client import HiveMessageBusClient
# not passing key etc so it uses identity file
client = HiveMessageBusClient(host="ws://localhost", port=5678)
client.connect() # establish a secure end-to-end encrypted connection
# to handle agent responses, use client.on_mycroft("event", handler)
answered = threading.Event()
def handle_speak(message: Message):
print(message.data['utterance'])
def utt_handled(message: Message):
answered.set()
client.on_mycroft("speak", handle_speak)
client.on_mycroft("ovos.utterance.handled", utt_handled)
while True:
utt = input("> ")
answered.clear()
client.emit(HiveMessage(HiveMessageType.BUS,
Message("recognizer_loop:utterance", {"utterances": [utt]})))
answered.wait()
```
### Example: Remote TTS
if server is running [hivemind-audio-binary-protocol](https://github.com/JarbasHiveMind/hivemind-audio-binary-protocol)
```python
from ovos_bus_client.message import Message
from hivemind_bus_client.client import BinaryDataCallbacks
from hivemind_bus_client.message import HiveMessage, HiveMessageType
from hivemind_bus_client.http_client import HiveMindHTTPClient
# To handle binary data subclass BinaryDataCallbacks
class BinaryDataHandler(BinaryDataCallbacks):
def handle_receive_tts(self, bin_data: bytes,
utterance: str,
lang: str,
file_name: str):
# we can play it or save to file or whatever
print(f"got {len(bin_data)} bytes of TTS audio")
print(f"utterance: {utterance}", f"lang: {lang}", f"file_name: {file_name}")
# got 33836 bytes of TTS audio
# utterance: hello world lang: en-US file_name: 5eb63bbbe01eeed093cb22bb8f5acdc3.wav
# not passing key etc so it uses identity file
client = HiveMindHTTPClient(host="http://localhost", port=5679,
bin_callbacks=BinaryDataHandler())
client.connect()
# send HiveMessages as usual
client.emit(HiveMessage(HiveMessageType.BUS,
Message("speak:synth", {"utterance": "hello world"})))
```
## Cli Usage
```bash
$ hivemind-client --help
Usage: hivemind-client [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
escalate escalate a single mycroft message
propagate propagate a single mycroft message
send-mycroft send a single mycroft message
terminal simple cli interface to inject utterances and print speech
$ hivemind-client set-identity --help
Usage: hivemind-client set-identity [OPTIONS]
persist node identity / credentials
Options:
--key TEXT HiveMind access key
--password TEXT HiveMind password
--siteid TEXT location identifier for message.context
--help Show this message and exit.
$ hivemind-client terminal --help
Usage: hivemind-client terminal [OPTIONS]
simple cli interface to inject utterances and print speech
Options:
--key TEXT HiveMind access key
--host TEXT HiveMind host
--port INTEGER HiveMind port number
--help Show this message and exit.
$ hivemind-client send-mycroft --help
Usage: hivemind-client send-mycroft [OPTIONS]
send a single mycroft message
Options:
--key TEXT HiveMind access key
--host TEXT HiveMind host
--port INTEGER HiveMind port number
--msg TEXT ovos message type to inject
--payload TEXT ovos message json payload
--help Show this message and exit.
$ hivemind-client escalate --help
Usage: hivemind-client escalate [OPTIONS]
escalate a single mycroft message
Options:
--key TEXT HiveMind access key
--host TEXT HiveMind host
--port INTEGER HiveMind port number
--msg TEXT ovos message type to inject
--payload TEXT ovos message json payload
--help Show this message and exit.
$ hivemind-client propagate --help
Usage: hivemind-client propagate [OPTIONS]
propagate a single mycroft message
Options:
--key TEXT HiveMind access key
--host TEXT HiveMind host
--port INTEGER HiveMind port number
--msg TEXT ovos message type to inject
--payload TEXT ovos message json payload
--help Show this message and exit.
```
Raw data
{
"_id": null,
"home_page": "https://github.com/JarbasHiveMind/hivemind_websocket_client",
"name": "hivemind-bus-client",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "JarbasAi",
"author_email": "jarbasai@mailfence.com",
"download_url": "https://files.pythonhosted.org/packages/c1/b5/18523ee3caaa9a9902dab00f6d38f5115ca016dd5910b10db256f854dcd7/hivemind_bus_client-0.4.3.tar.gz",
"platform": null,
"description": "# Hivemind Bus Client\n\nPython client library for [hivemind-core](https://github.com/JarbasHiveMind/HiveMind-core)\n\n## Install\n\n```bash\npip install hivemind_bus_client\n```\n\n## Usage\n\nvia [hivemind-http-protocol](https://github.com/JarbasHiveMind/hivemind-http-protocol)\n\n```python\nfrom hivemind_bus_client.http_client import HiveMindHTTPClient\n\n# not passing key etc so it uses identity file\nclient = HiveMindHTTPClient(host=\"http://localhost\", port=5679)\nclient.connect() # establish a secure end-to-end encrypted connection\n```\n\nvia [hivemind-websocket-protocol](https://github.com/JarbasHiveMind/hivemind-websocket-protocol)\n```python\nfrom hivemind_bus_client.client import HiveMessageBusClient\n\n# not passing key etc so it uses identity file\nclient = HiveMessageBusClient(host=\"ws://localhost\", port=5678)\nclient.connect() # establish a secure end-to-end encrypted connection\n```\n\n### Example: Simple Chat\n\n```python\nimport threading\nfrom ovos_bus_client.message import Message\nfrom hivemind_bus_client.message import HiveMessage, HiveMessageType\nfrom hivemind_bus_client.client import HiveMessageBusClient\n\n# not passing key etc so it uses identity file\nclient = HiveMessageBusClient(host=\"ws://localhost\", port=5678)\nclient.connect() # establish a secure end-to-end encrypted connection\n\n# to handle agent responses, use client.on_mycroft(\"event\", handler)\nanswered = threading.Event()\n\ndef handle_speak(message: Message):\n print(message.data['utterance'])\n\ndef utt_handled(message: Message):\n answered.set()\n\nclient.on_mycroft(\"speak\", handle_speak)\nclient.on_mycroft(\"ovos.utterance.handled\", utt_handled)\n\n\nwhile True:\n utt = input(\"> \")\n answered.clear()\n client.emit(HiveMessage(HiveMessageType.BUS,\n Message(\"recognizer_loop:utterance\", {\"utterances\": [utt]})))\n answered.wait()\n```\n\n### Example: Remote TTS \n\nif server is running [hivemind-audio-binary-protocol](https://github.com/JarbasHiveMind/hivemind-audio-binary-protocol)\n\n```python\nfrom ovos_bus_client.message import Message\nfrom hivemind_bus_client.client import BinaryDataCallbacks\nfrom hivemind_bus_client.message import HiveMessage, HiveMessageType\nfrom hivemind_bus_client.http_client import HiveMindHTTPClient\n\n# To handle binary data subclass BinaryDataCallbacks\nclass BinaryDataHandler(BinaryDataCallbacks):\n def handle_receive_tts(self, bin_data: bytes,\n utterance: str,\n lang: str,\n file_name: str):\n # we can play it or save to file or whatever\n print(f\"got {len(bin_data)} bytes of TTS audio\")\n print(f\"utterance: {utterance}\", f\"lang: {lang}\", f\"file_name: {file_name}\")\n # got 33836 bytes of TTS audio\n # utterance: hello world lang: en-US file_name: 5eb63bbbe01eeed093cb22bb8f5acdc3.wav\n\n\n# not passing key etc so it uses identity file\nclient = HiveMindHTTPClient(host=\"http://localhost\", port=5679,\n bin_callbacks=BinaryDataHandler())\nclient.connect()\n\n# send HiveMessages as usual\nclient.emit(HiveMessage(HiveMessageType.BUS,\n Message(\"speak:synth\", {\"utterance\": \"hello world\"})))\n\n```\n\n## Cli Usage\n\n```bash\n$ hivemind-client --help\nUsage: hivemind-client [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n --help Show this message and exit.\n\nCommands:\n escalate escalate a single mycroft message\n propagate propagate a single mycroft message\n send-mycroft send a single mycroft message\n terminal simple cli interface to inject utterances and print speech\n\n\n$ hivemind-client set-identity --help\nUsage: hivemind-client set-identity [OPTIONS]\n\n persist node identity / credentials\n\nOptions:\n --key TEXT HiveMind access key\n --password TEXT HiveMind password\n --siteid TEXT location identifier for message.context\n --help Show this message and exit.\n\n\n$ hivemind-client terminal --help\nUsage: hivemind-client terminal [OPTIONS]\n\n simple cli interface to inject utterances and print speech\n\nOptions:\n --key TEXT HiveMind access key\n --host TEXT HiveMind host\n --port INTEGER HiveMind port number\n --help Show this message and exit.\n\n\n$ hivemind-client send-mycroft --help\nUsage: hivemind-client send-mycroft [OPTIONS]\n\n send a single mycroft message\n\nOptions:\n --key TEXT HiveMind access key\n --host TEXT HiveMind host\n --port INTEGER HiveMind port number\n --msg TEXT ovos message type to inject\n --payload TEXT ovos message json payload\n --help Show this message and exit.\n\n\n$ hivemind-client escalate --help\nUsage: hivemind-client escalate [OPTIONS]\n\n escalate a single mycroft message\n\nOptions:\n --key TEXT HiveMind access key\n --host TEXT HiveMind host\n --port INTEGER HiveMind port number\n --msg TEXT ovos message type to inject\n --payload TEXT ovos message json payload\n --help Show this message and exit.\n\n\n$ hivemind-client propagate --help\nUsage: hivemind-client propagate [OPTIONS]\n\n propagate a single mycroft message\n\nOptions:\n --key TEXT HiveMind access key\n --host TEXT HiveMind host\n --port INTEGER HiveMind port number\n --msg TEXT ovos message type to inject\n --payload TEXT ovos message json payload\n --help Show this message and exit.\n\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Hivemind Websocket Client",
"version": "0.4.3",
"project_urls": {
"Homepage": "https://github.com/JarbasHiveMind/hivemind_websocket_client"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a1ff7be255119021ac9ee920062b349270b0bfcb901dd793b8a8de0e8ff6c722",
"md5": "077a2ad8fc0501834ed9b1f2a6057d13",
"sha256": "9eb1e967b8df07b3a08cf477a8b226760c62a1800c49e9294db2574d9a30bb3c"
},
"downloads": -1,
"filename": "hivemind_bus_client-0.4.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "077a2ad8fc0501834ed9b1f2a6057d13",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 43004,
"upload_time": "2025-02-07T16:24:58",
"upload_time_iso_8601": "2025-02-07T16:24:58.627418Z",
"url": "https://files.pythonhosted.org/packages/a1/ff/7be255119021ac9ee920062b349270b0bfcb901dd793b8a8de0e8ff6c722/hivemind_bus_client-0.4.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c1b518523ee3caaa9a9902dab00f6d38f5115ca016dd5910b10db256f854dcd7",
"md5": "7c8b47c84748f47e1d9e712c197e3f53",
"sha256": "4639b96c4565359de75b18eee379be092934e399a60b2057746ad3a31a613f29"
},
"downloads": -1,
"filename": "hivemind_bus_client-0.4.3.tar.gz",
"has_sig": false,
"md5_digest": "7c8b47c84748f47e1d9e712c197e3f53",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 37677,
"upload_time": "2025-02-07T16:25:00",
"upload_time_iso_8601": "2025-02-07T16:25:00.359527Z",
"url": "https://files.pythonhosted.org/packages/c1/b5/18523ee3caaa9a9902dab00f6d38f5115ca016dd5910b10db256f854dcd7/hivemind_bus_client-0.4.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-07 16:25:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "JarbasHiveMind",
"github_project": "hivemind_websocket_client",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "poorman-handshake",
"specs": [
[
">=",
"1.0.0"
],
[
"<",
"2.0.0"
]
]
},
{
"name": "ovos_bus_client",
"specs": [
[
">=",
"0.0.6a19"
]
]
},
{
"name": "ovos_utils",
"specs": [
[
">=",
"0.0.38"
]
]
},
{
"name": "bitstring",
"specs": [
[
">=",
"4.1.1"
]
]
},
{
"name": "cryptography",
"specs": [
[
">=",
"41.0.1"
]
]
},
{
"name": "pycryptodomex",
"specs": [
[
">=",
"3.18.0"
]
]
},
{
"name": "pybase64",
"specs": []
},
{
"name": "py-cpuinfo",
"specs": []
},
{
"name": "z85base91",
"specs": [
[
">=",
"0.0.5"
],
[
"<",
"1.0.0"
]
]
}
],
"lcname": "hivemind-bus-client"
}