Python sync client for BUS/RT
The module contains Python sync client for BUS/RT
Installation
pip3 install busrt
Usage examples
Listener
import busrt
import time
# frame handler
def on_frame(frame):
print('Frame:', hex(frame.type), frame.sender, frame.topic, frame.payload)
name = 'test.client.python.sync'
# create new BUS/RT client and connect
bus = busrt.client.Client('/tmp/busrt.sock', name)
bus.on_frame = on_frame
bus.connect()
# subscribe to all topics
bus.subscribe('#').wait_completed()
# wait for frames
print(f'listening for messages to {name}...')
while bus.is_connected():
time.sleep(0.1)
Sender
import busrt
name = 'test.client.python.sender'
bus = busrt.client.Client('/tmp/busrt.sock', name)
bus.connect()
# send a regular message
print(
hex(
bus.send('test.client.python.sync',
busrt.client.Frame('hello')).wait_completed()))
# send a broadcast message
print(
hex(
bus.send(
'test.*',
busrt.client.Frame('hello everyone',
tp=busrt.client.OP_BROADCAST)).wait_completed()))
# publish to a topic with zero QoS (no confirmation required)
bus.send('test/topic',
busrt.client.Frame('something', tp=busrt.client.OP_PUBLISH, qos=0))
RPC layer
Handler
import busrt
import time
import msgpack
# frame handler (topics/broadcasts)
def on_frame(frame):
print('Frame:', hex(frame.type), frame.sender, frame.topic, frame.payload)
# RPC notification handler
def on_notification(event):
print('Notification:', event.frame.sender, event.get_payload())
# RPC call handler
def on_call(event):
# consider payload is encoded in msgpack
print('Call:', event.frame.sender, event.method,
msgpack.loads(event.get_payload(), raw=False))
# msgpack reply
return msgpack.dumps({'ok': True})
name = 'test.client.python.sync.rpc'
# create new BUS/RT client and connect
bus = busrt.client.Client('/tmp/busrt.sock', name)
bus.connect()
# subscribe to all topics
bus.subscribe('#').wait_completed()
# init rpc
rpc = busrt.rpc.Rpc(bus)
rpc.on_frame = on_frame
rpc.on_notification = on_notification
rpc.on_call = on_call
# wait for frames
print(f'listening for messages/calls to {name}...')
while rpc.is_connected():
time.sleep(0.1)
Caller
import busrt
import msgpack
name = 'test.client.python.sync.rpc.caller'
# create new BUS/RT client and connect
bus = busrt.client.Client('/tmp/busrt.sock', name)
bus.connect()
# init rpc
rpc = busrt.rpc.Rpc(bus)
params = {'hello': 123}
# call a method, no reply required
rpc.call0('test.client.python.sync.rpc',
busrt.rpc.Request('test', msgpack.dumps(params))).wait_completed()
# call a method and wait for the reply
result = rpc.call('test.client.python.sync.rpc',
busrt.rpc.Request('test',
msgpack.dumps(params))).wait_completed()
print(msgpack.loads(result.get_payload(), raw=False))
Metadata
Release files for busrt 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| busrt-0.1.2.tar.gz | 6.7 kB | Without provenance | Details for busrt-0.1.2.tar.gz |
Release files / busrt-0.1.2.tar.gz
| Download URL | busrt-0.1.2.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db2a8193bbf54db8184f8d2002d8569b2c7cbbc39e46d90f1c2a88758451d609
|
|
BLAKE2b-256 checksum How to use checksums |
c55eacc91a119e22e2172b6347fe4b74395e7652fba4cabc06ac605aa15d1447
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.26.0 setuptools/60.5.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.8.10
|
Security for busrt 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.