Skip to main content

Mycroft Messagebus Client

Project description

Mycroft Bus Client

This module is a simple interface for the mycroft messagebus and can be used to connect to mycroft, send messages and react to messages sent by the Mycroft system.

MycroftBusClient()

The MycroftBusClient() object can be setup to connect to any host and port as well as any endpont on that host. this makes it quite versitile and will work on the main bus as well as on a gui bus. If no arguments are provided it will try to connect to a local instance of mycroftr core on the default endpoint and port.

Message()

The Message object is a representation of the messagebus message, this will always contain a message type but can also contain data and context. Data is usually real information while the context typically contain information on where the message originated or who the intended recipient is.

Message('MESSAGE_TYPE', data={'meaning': 42}, context={'origin': 'A.Dent'})

Examples

Below are some a couple of simple cases for sending a message on the bus as well as reacting to messages on the bus

Sending a message on the bus.

from mycroft_bus_client import MessageBusClient, Message

print('Setting up client to connect to a local mycroft instance')
client = MessageBusClient()
client.run_in_thread()

print('Sending speak message...')
client.emit(Message('speak', data={'utterance': 'Hello World'}))

Catching a message on the messagebus

from mycroft_bus_client import MessageBusClient, Message

print('Setting up client to connect to a local mycroft instance')
client = MessageBusClient()

def print_utterance(message):
    print('Mycroft said "{}"'.format(message.data.get('utterance')))


print('Registering handler for speak message...')
client.on('speak', print_utterance)

client.run_forever()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mycroft-messagebus-client-0.10.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

mycroft_messagebus_client-0.10.1-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file mycroft-messagebus-client-0.10.1.tar.gz.

File metadata

File hashes

Hashes for mycroft-messagebus-client-0.10.1.tar.gz
Algorithm Hash digest
SHA256 db7d2d08050d37112ccbf07381a7145f69e2a2cdb5d18d9b4322450e66c4f51b
MD5 466a910c1cd1b8ad80d10e92861d7822
BLAKE2b-256 75da3840283b54522c5fdf65d0c76a22a6194e0a03266399c9794cb861f06455

See more details on using hashes here.

File details

Details for the file mycroft_messagebus_client-0.10.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mycroft_messagebus_client-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ffb6a09c171586eb2bd07de3d5221d26725ce73a2dcbb418d2b8a2e4a7f59494
MD5 6c4e65c3ffed2545f5e6ad86809ca3d6
BLAKE2b-256 b3a45cd6333bf3ebd700abb8be59540f97dbb7bdf703195f9beb130a601c5867

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page