![]() |
[HOWTO] Using DBUS from Python on Sailfish OS
So turns out it's finally possible to easily use DBUS from Python applications on Sailfish OS via the (pure Python) Pydbus library. I'm familiar with Pydbus from using it in the Anaconda installer, so I've decided to give it a try on Sailfish OS as well.
And it turns to be really, really easy - I've got a client-server example running in ~5 minutes. So I've decided to write this short tutorial to get other started as well. :) From Zero to Python DBUS client/server in a few easy steps Requirements:
0) install the gobject-python3 package (required to use Pydbus): Code:
pkcon install python3-gobject 1) clone the pydbus repo: Code:
git clone https://github.com/LEW21/pydbus 2) in one shell run the server: Code:
cd pydbus 3) in the second shell run the client: Code:
cd pydbus 4) the client should get output like this (reply from the server & a string passed from the client and returned by the server): Code:
Hello, World! You can ignore the traceback at the end, it's caused by the example code being very simple, which includes simplified server shutdown. 5) you can also notice the server shutting down in the first shell as the client told it to quit over DBUS How is this useful for my application ?
You can use the D-Bus Inspector & Visual D-Bus applications (both available from Jolla Store) to explore available DBUS APIs and/or to test your own DBUS API. How do I integrate this with my Python application ? You need to include the python3-gobject package (available from official repositories) as a dependency of your application. Then just include pydbus (which is a pure-Python library) with your application code in the same manner as any other third party Python library. (Jolla developers said they preffer developers bindling pydbus with their applications rather than providing it from the official repositories as well.) Current issues
Feedback, correction & tutorial enhancements welcome! :) |
All times are GMT. The time now is 12:05. |
vBulletin® Version 3.8.8