Search code examples
pythonbindingglibgobjectpygobject

How to create python bindings for a glib/gobject based library


I would like to create Python3 bindings for a glib/gobject based library, namely infinote/libinfinity.

I am a bit puzzled about the necessary steps to accomplish this. Does PyGObject help here or not? Is this guide still valid for python3 and PyGObject?
If not, what do I need to read to understand how this will work?
Are there any tools to (semi-)automate the process?


Solution

  • You need GObject Introspection. Here is an overview page, and here are instructions on how to integrate it into your project if you use Autotools (which I see you do.)

    That's really all you need. Say you name your introspection repository Infinity-1.0.gir. Then, after building and installing, all you need to do in Python is

    from gi.repository import Infinity
    

    And presto, your library is now usable from Python.

    (PS. The guide you linked to is outdated.)