Overview — PyGObject (original) (raw)

_images/pygobject.svg _images/pygobject-dark.svg

PyGObject is a Python package which provides bindings for GObject based libraries such as GTK, GStreamer,WebKitGTK, GLib, GIO and many more.

It supports Linux, Windows, and macOS and works with Python 3.9+ andPyPy3. PyGObject, including this documentation, is licensed under theLGPLv2.1+.

Homepage

If you want to write a Python application for GNOME or a Python GUI application using GTK, then PyGObject is the way to go. To get started, check out the “GNOME Developer Documentation”. For more information on specific libraries, check out theGNOME Python API documentation.

import sys

import gi

gi.require_version("Gtk", "4.0") from gi.repository import GLib, Gtk

class MyApplication(Gtk.Application): def init(self): super().init(application_id="com.example.MyGtkApplication") GLib.set_application_name("My Gtk Application")

def do_activate(self):
    window = Gtk.ApplicationWindow(application=self, title="Hello World")
    window.present()

app = MyApplication() exit_status = app.run(sys.argv) sys.exit(exit_status)

How does it work?#

_images/overview.svg

_images/overview-dark.svg

PyGObject uses GLib, GObject, GIRepository, libffi and other libraries to access the C library (libgtk-4.so) in combination with the additional metadata from the accompanying typelib file (Gtk-4.0.typelib) and dynamically provides a Python interface based on that information.

Who Is Using PyGObject?#

The following applications or libraries use PyGObject for optional features, such as plugins or as optional backends:

Further Resources#

GNOME Developer Documentation

Tutorials for creating a GNOME application using PyGObject, GTK 4, and Libadwaita.

GNOME Python API documentation

Auto generated API documentation for many libraries accessible through PyGObject.