Registry / communication / dbus-python

dbus-python

JSON →
library1.4.0pypypiunverified

dbus-python provides Python bindings for libdbus, the reference implementation of the D-Bus inter-process communication (IPC) system. It enables Python applications to expose objects on the D-Bus and to invoke methods on objects exposed by other applications. The current version is 1.4.0, and releases are infrequent, typically aligned with updates to the underlying D-Bus specification or libdbus.

communicationhttp-networking
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

import dbus

While functional, `import dbus.service` is idiomatic to keep `dbus` namespace clear.

import dbus.service

You typically need the specific mainloop class, not just the module.

from dbus.mainloop.glib import DBusGMainLoop

This quickstart connects to the system D-Bus and queries the `org.freedesktop.DBus` service to list all currently active service names. This demonstrates basic bus connection, object retrieval, and method invocation. For services that require asynchronous operations (e.g., listening for signals or exposing Python objects), integration with a main event loop (like GLib or Qt) is necessary.

import dbus try: # Connect to the system bus # Use dbus.SessionBus() for the user's session bus bus = dbus.SystemBus() # Get the D-Bus 'org.freedesktop.DBus' interface on the bus obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus') # Get the 'org.freedesktop.DBus' interface itself iface = dbus.Interface(obj, 'org.freedesktop.DBus') # Call the ListNames method to get active service names names = iface.ListNames() print("Currently active D-Bus service names (system bus):") for name in names: print(f"- {name}") except dbus.exceptions.DBusException as e: print(f"Error connecting to D-Bus or listing names: {e}") print("Ensure the D-Bus daemon is running and you have appropriate permissions.") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known footguns
breakingdbus-python 1.x is Python 3 ONLY. Older versions (e.g., 0.8x) supported Python 2. Directly upgrading from an old Python 2 environment will break existing code.
gotchadbus-python requires the underlying C library `libdbus` to be installed on the system. `pip install dbus-python` will install the Python package but will fail at runtime if `libdbus` is missing.
gotchaFor D-Bus services that emit signals or require asynchronous handling (e.g., exposing Python objects), `dbus-python` must be integrated with an event loop (e.g., GLib, Qt, Gtk). Without it, your D-Bus service will not respond to calls or process signals.
gotchaD-Bus concepts (Bus, Object Paths, Interfaces, Service Names) are fundamental. Misunderstanding these often leads to connection errors or services not being found.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources