dbus-fast
dbus-fast is a high-performance Python library for interacting with the D-Bus message bus, providing an asynchronous API built on `asyncio`. It aims to be a faster and more modern alternative to older D-Bus libraries, focusing on speed and comprehensive type-hinting support. Currently at version 4.0.4, it maintains a rapid release cadence with frequent updates and bug fixes.
Warnings
- breaking The representation of D-Bus STRUCT types changed from Python lists to tuples.
- gotcha dbus-fast requires Python 3.10 or newer.
- gotcha dbus-fast is an asynchronous library and requires careful use of `async`/`await` within an `asyncio` event loop. Forgetting `await` or not running in a loop will lead to errors.
- gotcha Accessing the D-Bus system bus (BusType.SYSTEM) often requires specific user permissions or group memberships, which can lead to `dbus_fast.errors.DbusError` (e.g., 'org.freedesktop.DBus.Error.AccessDenied').
Install
-
pip install dbus-fast
Imports
- MessageBus
from dbus_fast.aio import MessageBus
- BusType
from dbus_fast.constants import BusType
- ServiceInterface
from dbus_fast.service import ServiceInterface, method, dbus_property, signal
- Variant
from dbus_fast import Variant
Quickstart
import asyncio
from dbus_fast.aio import MessageBus
from dbus_fast.constants import BusType
async def main():
# Connect to the system bus. For the user session bus, use BusType.SESSION.
bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
try:
reply = await bus.call(
bus_name="org.freedesktop.DBus",
path="/org/freedesktop/DBus",
interface="org.freedesktop.DBus",
member="ListNames",
)
names = reply.body[0]
print("D-Bus names on system bus:", names)
except Exception as e:
print(f"Error calling ListNames on system bus: {e}")
print("Note: Access to the system bus typically requires specific permissions (e.g., being in a 'wheel' group or root).")
finally:
await bus.disconnect()
if __name__ == "__main__":
# Ensure this runs in an async context
asyncio.run(main())