Skip to main content

Python bindings for libubus

Project description

Code in this directory enables a subset of libubus functions to be used directly from python.


To install these bidning you need to have the following libraries and headers installed:

  • libubox

  • libubus

  • python/python3


connect and disconnect

To connect you need to:

import ubus

To disconnect you can simply:


Note that calling connect()/disconnect() on opened/closed connection will throw an exception.


To add an object to ubus you can (you need to become root first):

def callback(handler, data):
    handler.reply(data)  # this should return exactly the same data to the caller

    "my_object", {
        "my_method": {"method": callback, "signature": {
                "first": ubus.BLOBMSG_TYPE_STRING,
                "second": ubus.BLOBMSG_TYPE_BOOL,
                "third": ubus.BLOBMSG_TYPE_INT32,

You need to enter the loop to serve the object methods afterwards:


Note that it might not be a good idea to call the callback function recursively.


To list the objects which are currently connected to ubus you can call:



{u'my_object': {u'my_method': {u'first': 3, u'second': 7, u'third': 5}}}


To call an actual method on an object you can use:"my_object", "my_method", {"first": "my_string", "second": True, "third": 42})


[{"first": "my_string", "second": True, "third": 42}]


To listen for an event you can:

def callback(event, data):
    print(event, data)  # just print event name and data to stdout

ubus.listen(("my_event", callback))

And you need to enter the loop to start to listen:


Note that it might not be a good idea to call the callback function recursively.


This will send an event to ubus:

ubus.send("my_event", {"some": "data"})


There are some tests present (‘tests/’ directory). So feel free to check it for some more complex examples. To run the tests you need to have ubus installed and become root:

sudo python test

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

ubus-0.1.1.tar.gz (11.9 kB view hashes)

Uploaded Source

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