Skip to main content

Ask DeepWiki

Hivemind Client

Python client library for hivemind-core

Install

pip install hivemind_bus_client

Usage

via hivemind-http-protocol

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

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

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

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

$ 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.

Metadata

Release files for hivemind-bus-client 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hivemind-bus-client 0.4.4
File Size Uploaded
hivemind_bus_client-0.4.4.tar.gz 38.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hivemind-bus-client 0.4.4
File Interpreter ABI Platform
hivemind_bus_client-0.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 82.6 kB

Release files / hivemind_bus_client-0.4.4.tar.gz

Download URL hivemind_bus_client-0.4.4.tar.gz
Size 38.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d5983261c33067a8122526df1bccfada89bce1bedae4d6342d323d9c1906ec6b
BLAKE2b-256 checksum
How to use checksums
22c9708a4f4923cddcd682d1a2e267398e1e4e2c4ef94acb2ab32efe900c3fa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / hivemind_bus_client-0.4.4-py3-none-any.whl

Download URL hivemind_bus_client-0.4.4-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a0d66f0fd44a1166907a522a5bbb0d49a3de96704f7a12c49cc6ec959a6a80d
BLAKE2b-256 checksum
How to use checksums
ce110f6785dde0ad0f94feb8ad43c2288fc6c18d94d5af734626d699c0c80aff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.4.4 This release

2 release files

0.4.3

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.4

2 release files

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page