dbus-fast

4.0.4 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to connect to the D-Bus system bus and call the standard `ListNames` method on the D-Bus daemon. It prints the names of currently registered services. Remember to run this in an `asyncio` event loop.

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())

view raw JSON →