Wednesday, May 5, 2010

Using telepathy-glib in python through gobject-introspection

Until now, you had two options for writing telepathy clients in python: use the low level D-Bus API through dbus-python, or using telepathy-python which provided very little more for clients apart from registering the zillion of constants in Telepathy.

Telepathy-glib is a library that provides a higher level API for interacting with the Telepathy framework than the low level D-Bus API. No languages bindings exist currently for this library so only C apps such as Empathy used it, developers using languages such as Python and JavaScript were stuck with the D-Bus API and generally each app invented a more or less complete new API on top of it.

In parallel to a push for adding more high-level APIs to telepathy-glib, we are looking at what remains to be done in the gobject-introspection stack so we don't need to write static bindings for each language. After some weeks hacking on Gjs (Danielle Madeley), Vala (Travis Reitter) and PyGI (me) things are starting to take shape.

Following Danni's post on her progress, here comes an example observer written in Python and using PyGI to call telepathy-glib:

import gobject

from gi.repository import TelepathyGLib


def observe_channels(observer, account, connection, channels,
dispatch_op, requests, context, user_data):
print 'observe_channels'

print 'account = %s' % account.get_object_path()
print 'connection = %s' % connection.get_object_path()

for channel in channels:
print 'channel = %s' % channel.get_object_path()

if dispatch_op is not None:
print 'dispatch_op = %s' % dispatch_op.get_object_path()
print 'dispatch_op = None'

if requests is not None:
for request in requests:
print 'request = %s' % request.get_object_path()


dbus = TelepathyGLib.DBusDaemon.dup()
observer =, True, 'PythonObserver', True,
observe_channels, None)


main_loop = gobject.MainLoop()

This needs the latest code in telepathy-glib, gobject-introspection and pygi, and also a patch to PyGI that hasn't been release yet.


luismarianoguerra said...

hi, I'm doing a gtk application and I would like start porting it to python 3, can I use pygi to use gtk in python 3?

how is the status of the port?

cay you point me to some link that helps me get started?

Tomeu Vizoso said...


Hi, the state of the port is such that we have patches for PyGObject and PyGI that passes the tests with Python 3, see for links:

We will appreciate help pushing this forward!