Replies: 2 comments 1 reply
-
Here are some (raw) test results from at least some of the packages tested. For the tests, I used the following D-Bus service, object, interface and method:
Test for need for import os
del os.environ['DBUS_SESSION_BUS_ADDRESS'] to the top of the test script. ResultsjeepneyJeepneyfrom jeepney import DBusAddress, new_method_call
from jeepney.io.blocking import open_dbus_connection
proxy = DBusAddress('/org/freedesktop/DBus',
bus_name='org.freedesktop.DBus',
interface='org.freedesktop.DBus')
connection = open_dbus_connection(bus='SESSION')
msg = new_method_call(proxy, 'ListNames')
reply = connection.send_and_get_reply(msg)
print(reply.body[0])
dbus-pythondbus-pythonInstalling in venv does not work directly:
PyGObjectPyGObject
dbus-nextdbus-nextimport asyncio
from dbus_next.aio import MessageBus
from dbus_next.message import Message
async def main():
bus = await MessageBus().connect()
msg = Message(destination='org.freedesktop.DBus',
path='/org/freedesktop/DBus',
interface='org.freedesktop.DBus',
member='ListNames')
return await bus.call(msg)
reply = asyncio.run(main())
print(reply.body[0])
In [1]: from dbus_next.glib import MessageBus
In [2]: MessageBus()
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[2], line 1
----> 1 MessageBus()
File ~/tmp/venv/lib/python3.10/site-packages/dbus_next/glib/message_bus.py:154, in MessageBus.__init__(self, bus_address, bus_type, auth)
149 def __init__(self,
150 bus_address: str = None,
151 bus_type: BusType = BusType.SESSION,
152 auth: Authenticator = None):
153 if _import_error:
--> 154 raise _import_error
156 super().__init__(bus_address, bus_type, ProxyObject)
157 self._main_context = GLib.main_context_default()
File ~/tmp/venv/lib/python3.10/site-packages/dbus_next/glib/message_bus.py:17
15 _import_error = None
16 try:
---> 17 from gi.repository import GLib
18 _GLibSource = GLib.Source
19 except ImportError as e:
ModuleNotFoundError: No module named 'gi' pydbuspydbusfrom pydbus import SessionBus
session_bus = SessionBus()
proxy = bus.get('org.freedesktop.DBus',
'/org/freedesktop/DBus')
interface = proxy['org.freedesktop.DBus']
interface.ListNames() Depends on PyGObject:
sdbussdbusfrom sdbus import DbusInterfaceCommon, dbus_method
class Interface(DbusInterfaceCommon,
interface_name='org.freedesktop.DBus'):
@dbus_method()
def ListNames(self) -> str:
raise NotImplementedError
iface = Interface(
service_name='org.freedesktop.DBus',
object_path='/org/freedesktop/DBus',
)
print(iface.ListNames())
dasbusdasbus
dbussydbussyimport ravel # part of dbussy
conn = ravel.session_bus()
peer = conn['org.freedesktop.DBus']
obj = peer['/org/freedesktop/DBus']
iface = obj.get_interface('org.freedesktop.DBus')
results = iface.ListNames()
print(results)
pystemdpystemd
pysdbuspysdbus
import dbus
bus = dbus.SessionBus()
obj = bus.getObject("org.freedesktop.DBus", "/org/freedesktop/DBus")
iface = obj.getInterface("org.freedesktop.DBus")
reply = iface.ListNames()
print(reply)
|
Beta Was this translation helpful? Give feedback.
-
Hello, author of python-sdbus here.
Python-sdbus also supports the elogind when available during compile time. (meaning Alpine Linux is supported) The PyPI package however is linked against glibc so without compiling during installation only glibc based distros are available.
The license is LGPL-2.1-or-later but the GPL-2.0 text is included because LGPL is an extension of GPL and requires the text of GPL to be present. |
Beta Was this translation helpful? Give feedback.
-
Just wanted to write down some of my notes from comparison of multiple different python dbus implementations. The meaning of the column names are:
DBUS_SESSION_BUS_ADDRESS
environment variable would be missing. Not sure if this is good thing or not (where is the address then taken from..?)Footnotes
[1] Zero dependency (python or any other) package
[2] Required libdbus. Has .c and .h files in source, so needs to be compiled.
[3] Zero dependency (python or any other) package on
dbus_next.aio
(async side)[4] sdbus wheel in PyPi is statically linked with libsystemd, but it is also possible to compile against libelogind (for Alpine/other elogind based systems). See this comment. Does not use ctypes or dynamic linking.
[5] Abandoned? Last commit from 2018.
[6] Aka. python-sdbus
[7] Note that PyGObject (aka. PyGI or python-gi. Imported as
gi
) does not install easily, either. The dependencies are listed in the documentation.Yet other alternatives
Comments
pip install
command". In other words, installs well without a need for installing e.g. non-python dependencies. Most packages with other than python (e.g C) code, if not delivering wheels for the system, will have difficulties when installing. A package which would not install without effort in new virtual environment is not very appealing candidate for a dependency (or dependency of a dependency..)Edits to this post
2024-04-29: Corrected the python-sdbus license to LGPL-2.1-or-later. Added note about libelogind option.Beta Was this translation helpful? Give feedback.
All reactions