DBUS Introspection

Small snippet to get all the methods an DBus object supports:

from dbus import SessionBus, Interface
from dbus.introspect_parser import process_introspection_data

def introspect_object(named_service, object_path):
    obj = SessionBus().get_object(named_service, object_path)
    iface = Interface(obj, 'org.freedesktop.DBus.Introspectable')
    return process_introspection_data(iface.Introspect())

Example usage:

>>> introspect_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Shell')
{'org.freedesktop.DBus.Introspectable.Introspect': '',
 'org.freedesktop.DBus.Properties.Get': 'ss',
 'org.freedesktop.DBus.Properties.Set': 'ssv',
 'org.gnome.Rhythmbox.Shell.addToQueue': 's',
 'org.gnome.Rhythmbox.Shell.clearQueue': '',
 'org.gnome.Rhythmbox.Shell.getPlayer': '',
 'org.gnome.Rhythmbox.Shell.getPlaylistManager': '',
 'org.gnome.Rhythmbox.Shell.getSongProperties': 's',
 'org.gnome.Rhythmbox.Shell.loadURI': 'sb',
 'org.gnome.Rhythmbox.Shell.present': 'u',
 'org.gnome.Rhythmbox.Shell.quit': '',
 'org.gnome.Rhythmbox.Shell.removeFromQueue': 's',
 'org.gnome.Rhythmbox.Shell.setSongProperty': 'ssv'}

Unfortunately this does not show the names of the arguments, just the types thereof. If you remove the process_introspection_data call you get back a string with the XML data containing all the introspection information. You can then parse it on your own, the format is straightforward.

Leave a Reply

cogitations driven by wordpress