Python bindings for ubus
Code in this directory enables a subset of libubus functions to be used directly from python.
Installation
To install these bidning you need to have the following libraries and headers installed:
libubox
libubus
python/python3
Examples
connect and disconnect
To connect you need to:
import ubus
ubus.connect("/var/run/ubus/ubus.sock")
To disconnect you can simply:
ubus.disconnect()
Note that calling connect()/disconnect() on opened/closed connection will throw an exception.
add
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
ubus.add(
"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:
ubus.loop()
Note that it might not be a good idea to call the callback function recursively.
objects
To list the objects which are currently connected to ubus you can call:
ubus.objects()
->
{u'my_object': {u'my_method': {u'first': 3, u'second': 7, u'third': 5}}}
call
To call an actual method on an object you can use:
ubus.call("my_object", "my_method", {"first": "my_string", "second": True, "third": 42})
->
[{"first": "my_string", "second": True, "third": 42}]
listen
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:
ubus.loop()
Note that it might not be a good idea to call the callback function recursively.
send
This will send an event to ubus:
ubus.send("my_event", {"some": "data"})
Notes
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 setup.py test
Metadata
Release files for ubus 0.1.3
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 |
|---|---|---|---|---|
| ubus-0.1.3.tar.gz | 24.3 kB | Without provenance | Details for ubus-0.1.3.tar.gz |
Release files / ubus-0.1.3.tar.gz
| Download URL | ubus-0.1.3.tar.gz |
|---|---|
| Size | 24.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e737ae171b38836c26bc3e50e9c468afd47d9cc8bc01f33a5b569a05e1d8567f
|
|
BLAKE2b-256 checksum How to use checksums |
99e806c8f9e69fb3463c5670c1ad05f9f81a982bbcd4a6df9fb8c4c36d38e83c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Security for ubus 0.1.3
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.