dbus-next is a pure Python 3 library for the D-Bus message bus system, designed for interprocess communication in Linux desktop and mobile environments. It boasts zero dependencies and offers first-class asyncio support, along with an optional GLib main loop backend. It's a modern alternative to older D-Bus bindings, providing high-level client and service interfaces, and is currently at version 0.2.3 with an active development and release cadence.
pip install dbus-nextVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates connecting to the D-Bus session bus and interacting with a media player using the MPRIS (Media Player Remote Interfacing Specification) interface. It showcases how to connect to the bus, introspect an object, obtain a proxy interface, call a method, and read a property.
Instead of `MessageBus.session_bus()` or `MessageBus.system_bus()`, use `await MessageBus().connect()` for the session bus or `await MessageBus(bus_type=BusType.SYSTEM).connect()` for the system bus.
Ensure all method arguments and return types in `ServiceInterface` subclasses are annotated with D-Bus type signatures (e.g., `def my_method(self, value: 's') -> 'b':`). This is crucial for correct type marshalling.
Always use `bus = await MessageBus().connect()` rather than `bus = MessageBus().connect()`. Forgetting `await` will result in a `TypeError` if you try to use the returned coroutine object directly.
To send or receive Unix file descriptors, you must set `negotiate_unix_fd=True` in the `MessageBus` constructor (e.g., `MessageBus(negotiate_unix_fd=True)`). You are responsible for closing any received file descriptors.
Replace `MessageBus.session_bus()` or `MessageBus.system_bus()` with `await MessageBus().connect()` or `await MessageBus(bus_type=BusType.SYSTEM).connect()` respectively.
Add appropriate D-Bus type signature string annotations to all parameters and return values of service interface methods. Example: `def my_method(self, name: 's') -> 's':`.
Ensure that `MessageBus().connect()` is called with the `await` keyword: `bus = await MessageBus().connect()`.
Verify that the D-Bus service you intend to interact with is running and correctly exporting the expected interface at the specified object path. Use `qdbusviewer` or `busctl` to inspect available services and interfaces on your system.