Active Topics



Thread Tools
Posts: 1,491 | Thanked: 7,139 times | Joined on Apr 2010 @ Czech Republic
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

  • Sailfish OS device with up to date Salfish OS install (2.1.3+)
  • being able to install packages from official repos
  • being able to run 2 concurrent shell sessions (2 SSH connections, screen, tmux, etc.)

0) install the gobject-python3 package (required to use Pydbus):

pkcon install python3-gobject

1) clone the pydbus repo:

git clone

2) in one shell run the server:

cd pydbus
PYTHONPATH=. python3 examples/clientserver/

3) in the second shell run the client:
cd pydbus
PYTHONPATH=. python3 examples/clientserver/

4) the client should get output like this (reply from the server & a string passed from the client and returned by the server):

Hello, World!
test 123
Traceback (most recent call last):
  File "examples/clientserver/", line 21, in <module>
  File "/home/nemo/software/pydbus/pydbus/", line 75, in __call__
    0, timeout_to_glib(timeout), None).unpack()
gi._glib.GError: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying

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 ?
  • the server part of the example can be used for providing a DBUS API from PYthon applications to other Sailfish OS applications (for example a DBUS API for a maping application to focus on a set of coordinates, etc.)
  • the client part of the example can be used by Python applications to connect to existing Sailfish OS DBUS APIs (both the system & various applications provide DBUS APIs)

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
  • apparently not Harbour compatible yet (""No OS version and packages satisfy package requirements: Requirement python3-gobject not available") but I have not checked for this myself

Feedback, correction & tutorial enhancements welcome!
modRana: a flexible GPS navigation system
Mieru: a flexible manga and comic book reader
Universal Components - a solution for native looking yet component set independent QML appliactions (QtQuick Controls 2 & Silica supported as backends)

The Following 11 Users Say Thank You to MartinK For This Useful Post:

howto, pydbus, python, sailfishos, tutorial

Thread Tools

Forum Jump

All times are GMT. The time now is 03:05.