diff --git a/gio/Makefile.am b/gio/Makefile.am
index 48b7a97..a080cd0 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -55,7 +55,7 @@ CLEANFILES += gio.c
 EXTRA_DIST += $(GIO_DEFS) $(GIO_OVERRIDES)
 gio.c: $(GIO_DEFS) $(GIO_OVERRIDES)
 _gio_la_CFLAGS = $(GIO_CFLAGS)
-_gio_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_gio
+_gio_la_LDFLAGS = $(common_ldflags) -export-symbols-regex "_gio|PyInit__gio"
 _gio_la_LIBADD = $(GIO_LIBS) $(top_builddir)/glib/libpyglib-2.0.la
 _gio_la_SOURCES = \
 	giomodule.c \
@@ -72,17 +72,16 @@ GIOUNIX_DEFS = unix.defs unix-types.defs unix.override
 CLEANFILES += unix.c
 EXTRA_DIST += $(GIOUNIX_DEFS) unix.override
 giounix.c: $(GIOUNIX_DEFS) unix.override
-unix_la_CFLAGS = $(GIOUNIX_CFLAGS)
-unix_la_LDFLAGS = $(common_ldflags) -export-symbols-regex initunix
-unix_la_LIBADD = $(GIOUNIX_LIBS)
-unix_la_SOURCES = unixmodule.c
-nodist_unix_la_SOURCES = unix.c
+_unix_la_CFLAGS = $(GIOUNIX_CFLAGS)
+_unix_la_LDFLAGS = $(common_ldflags) -export-symbols-regex "unix|PyInit__unix"
+_unix_la_LIBADD = $(GIOUNIX_LIBS)
+_unix_la_SOURCES = unixmodule.c
+nodist__unix_la_SOURCES = unix.c
 if BUILD_GIOUNIX
-pkgpyexec_LTLIBRARIES += unix.la
+pkgpyexec_LTLIBRARIES += _unix.la
 defs_DATA += $(GIOUNIX_DEFS)
 endif
 
-
 # code generator
 .defs.c:
 	(cd $(srcdir)\
@@ -91,7 +90,7 @@ endif
 	    --register gio-types.defs \
 	    --register unix-types.defs \
 	    --override $*.override \
-	    --prefix py$(*F) $*.defs) > $(*D)/gen-$(*F).c \
+	    --prefix _$(*F) $*.defs) > $(*D)/gen-$(*F).c \
 	&& cp $(*D)/gen-$(*F).c $(*D)/$(*F).c \
 	&& rm -f $(*D)/gen-$(*F).c
 
diff --git a/gio/__init__.py b/gio/__init__.py
index c4b02bb..e44b4aa 100644
--- a/gio/__init__.py
+++ b/gio/__init__.py
@@ -20,15 +20,17 @@
 # USA
 
 from gobject import GObjectMeta
-from _gio import *
-from _gio import \
+from gio._gio import *
+from gio._gio import \
      _app_info_init, _install_app_info_meta, \
      _file_init, _install_file_meta
 try:
-    import unix
-    unix # pyflakes
+    from gio import _unix 
+    _unix # pyflakes
 except ImportError:
     unix = None
+else:
+    unix = _unix
 del _gio
 
 class GFileMeta(GObjectMeta):
diff --git a/gio/gappinfo.override b/gio/gappinfo.override
index 414769b..81caf8e 100644
--- a/gio/gappinfo.override
+++ b/gio/gappinfo.override
@@ -31,7 +31,7 @@ _wrap__install_app_info_meta(PyObject *self, PyObject *args)
 	return NULL;
 
     Py_INCREF(metaclass);
-    PyGAppInfo_Type.ob_type = (PyTypeObject*)metaclass;
+    Py_TYPE(&PyGAppInfo_Type) = (PyTypeObject*)metaclass;
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -199,10 +199,10 @@ _wrap_g_app_info_tp_repr(PyGObject *self)
     PyObject *result;
 
     representation = g_strdup_printf("<%s at %p: %s>",
-				     self->ob_type->tp_name, self,
+				     Py_TYPE(self)->tp_name, self,
 				     name ? name : "UNKNOWN NAME");
 
-    result = PyString_FromString(representation);
+    result = _PyUnicode_FromString(representation);
     g_free(representation);
     return result;
 }
diff --git a/gio/gapplaunchcontext.override b/gio/gapplaunchcontext.override
index a10f959..2e30702 100644
--- a/gio/gapplaunchcontext.override
+++ b/gio/gapplaunchcontext.override
@@ -53,7 +53,7 @@ _wrap_g_app_launch_context_get_display(PyGObject *self,
     g_list_free(file_list);
 
     if (ret)
-        return PyString_FromString(ret);
+        return _PyUnicode_FromString(ret);
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -92,7 +92,7 @@ _wrap_g_app_launch_context_get_startup_notify_id(PyGObject *self,
     g_list_free(file_list);
 
     if (ret)
-        return PyString_FromString(ret);
+        return _PyUnicode_FromString(ret);
 
     Py_INCREF(Py_None);
     return Py_None;
diff --git a/gio/gdrive.override b/gio/gdrive.override
index 4fb8a1e..1af44a1 100644
--- a/gio/gdrive.override
+++ b/gio/gdrive.override
@@ -147,15 +147,16 @@ _wrap_g_drive_tp_repr(PyGObject *self)
     char *name = g_drive_get_name(G_DRIVE(self->obj));
     gchar *representation;
     PyObject *result;
+    PyObject *pyself = (PyObject*) self->obj;
 
     if (name) {
-	representation = g_strdup_printf("<%s at %p: %s>", self->ob_type->tp_name, self, name);
+	representation = g_strdup_printf("<%s at %p: %s>", pyself->ob_type->tp_name, self, name);
 	g_free(name);
     }
     else
-	representation = g_strdup_printf("<%s at %p: UNKNOWN NAME>", self->ob_type->tp_name, self);
+	representation = g_strdup_printf("<%s at %p: UNKNOWN NAME>", pyself->ob_type->tp_name, self);
 
-    result = PyString_FromString(representation);
+    result = _PyUnicode_FromString(representation);
     g_free(representation);
     return result;
 }
diff --git a/gio/gfile.override b/gio/gfile.override
index e7844e3..86653ce 100644
--- a/gio/gfile.override
+++ b/gio/gfile.override
@@ -62,7 +62,7 @@ _wrap__install_file_meta(PyObject *self, PyObject *args)
 	return NULL;
 
     Py_INCREF(metaclass);
-    PyGFile_Type.ob_type = (PyTypeObject*)metaclass;
+    Py_TYPE(&PyGFile_Type) = (PyTypeObject*)metaclass;
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -1138,7 +1138,7 @@ _wrap_g_file_replace_contents(PyGObject *self, PyObject *args, PyObject *kwargs)
         return NULL;
 
     if (ret) {
-        py_ret = PyString_FromString(new_etag);
+        py_ret = _PyUnicode_FromString(new_etag);
     } else {
         py_ret = Py_None;
         Py_INCREF(py_ret);
@@ -1174,7 +1174,7 @@ _wrap_g_file_replace_contents_finish(PyGObject *self, PyObject *args, PyObject *
         return NULL;
 
     if (ret) {
-        py_ret = PyString_FromString(etag_out);
+        py_ret = _PyUnicode_FromString(etag_out);
         return py_ret;
     } else {
         py_ret = Py_None;
@@ -1294,13 +1294,13 @@ _wrap_g_file_tp_repr(PyGObject *self)
     PyObject *result;
 
     if (uri) {
-	representation = g_strdup_printf("<%s at %p: %s>", self->ob_type->tp_name, self, uri);
+	representation = g_strdup_printf("<%s at %p: %s>", Py_TYPE(self)->tp_name, self, uri);
 	g_free(uri);
     }
     else
-	representation = g_strdup_printf("<%s at %p: UNKNOWN URI>", self->ob_type->tp_name, self);
+	representation = g_strdup_printf("<%s at %p: UNKNOWN URI>", Py_TYPE(self)->tp_name, self);
 
-    result = PyString_FromString(representation);
+    result = _PyUnicode_FromString(representation);
     g_free(representation);
     return result;
 }
diff --git a/gio/gfileattribute.override b/gio/gfileattribute.override
index e51ec63..f641b2e 100644
--- a/gio/gfileattribute.override
+++ b/gio/gfileattribute.override
@@ -52,7 +52,7 @@ pyg_file_attribute_info__get_name(PyObject *self, void *closure)
 
     ret = ((PyGFileAttributeInfo*)self)->info->name;
     if (ret)
-        return PyString_FromString(ret);
+        return _PyUnicode_FromString(ret);
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -82,52 +82,55 @@ static const PyGetSetDef pyg_file_attribute_info_getsets[] = {
     { NULL, (getter)0, (setter)0 },
 };
 
-PyTypeObject PyGFileAttributeInfo_Type = {
-    PyObject_HEAD_INIT(NULL)
-    0,                                  /* ob_size */
-    "gio.FileAttributeInfo",            /* tp_name */
-    sizeof(PyGFileAttributeInfo),      /* tp_basicsize */
-    0,                                  /* tp_itemsize */
+PyTypeObject G_GNUC_INTERNAL PyGFileAttributeInfo_Type = {
+    PyVarObject_HEAD_INIT(NULL, 0)
+    "gio.FileAttributeInfo",                   /* tp_name */
+    sizeof(PyGFileAttributeInfo),          /* tp_basicsize */
+    0,                                 /* tp_itemsize */
     /* methods */
-    (destructor)0,                      /* tp_dealloc */
-    (printfunc)0,                       /* tp_print */
-    (getattrfunc)0,                     /* tp_getattr */
-    (setattrfunc)0,                     /* tp_setattr */
-    (cmpfunc)0,                         /* tp_compare */
-    (reprfunc)0,                        /* tp_repr */
-    0,                                  /* tp_as_number */
-    0,                                  /* tp_as_sequence */
-    0,                                  /* tp_as_mapping */
-    (hashfunc)0,                        /* tp_hash */
-    (ternaryfunc)0,                     /* tp_call */
-    (reprfunc)0,                        /* tp_str */
-    (getattrofunc)0,                    /* tp_getattro */
-    (setattrofunc)0,                    /* tp_setattro */
-    0,                                  /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
-    "Holds information about an attribute", /* Documentation string */
-    (traverseproc)0,                    /* tp_traverse */
-    (inquiry)0,                         /* tp_clear */
-    (richcmpfunc)0,                     /* tp_richcompare */
-    0,                                  /* tp_weaklistoffset */
-    (getiterfunc)0,                     /* tp_iter */
-    (iternextfunc)0,                    /* tp_iternext */
-    (struct PyMethodDef*)pyg_file_attribute_info_methods,    /* tp_methods */
-    0,                                  /* tp_members */
-    (struct PyGetSetDef*)pyg_file_attribute_info_getsets,    /* tp_getset */
-    (PyTypeObject *)0,                  /* tp_base */
-    (PyObject *)0,                      /* tp_dict */
-    0,                                  /* tp_descr_get */
-    0,                                  /* tp_descr_set */
-    0,                                  /* tp_dictoffset */
-    (initproc)0,                        /* tp_init */
-    0,                                  /* tp_alloc */
-    (newfunc)pygio_file_attribute_info_tp_new,   /* tp_new */
-    0,                                  /* tp_free */
-    (inquiry)0,                         /* tp_is_gc */
-    (PyObject *)0,                      /* tp_bases */
+    (destructor)0,        /* tp_dealloc */
+    (printfunc)0,                      /* tp_print */
+    (getattrfunc)0,       /* tp_getattr */
+    (setattrfunc)0,       /* tp_setattr */
+#if PY_VERSION_HEX < 0x03000000
+    (cmpfunc)0,           /* tp_compare */
+#else
+    NULL,
+#endif
+    (reprfunc)0,             /* tp_repr */
+    (PyNumberMethods*)0,     /* tp_as_number */
+    (PySequenceMethods*)0, /* tp_as_sequence */
+    (PyMappingMethods*)0,   /* tp_as_mapping */
+    (hashfunc)0,             /* tp_hash */
+    (ternaryfunc)0,          /* tp_call */
+    (reprfunc)0,              /* tp_str */
+    (getattrofunc)0,     /* tp_getattro */
+    (setattrofunc)0,     /* tp_setattro */
+    (PyBufferProcs*)0,  /* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT,                       /* tp_flags */
+    "Holds information about an attribute",                        /* Documentation string */
+    (traverseproc)0,     /* tp_traverse */
+    (inquiry)0,             /* tp_clear */
+    (richcmpfunc)0,   /* tp_richcompare */
+    0,             /* tp_weaklistoffset */
+    (getiterfunc)0,          /* tp_iter */
+    (iternextfunc)0,     /* tp_iternext */
+    (struct PyMethodDef*)pyg_file_attribute_info_methods, /* tp_methods */
+    (struct PyMemberDef*)0,              /* tp_members */
+    (struct PyGetSetDef*)pyg_file_attribute_info_getsets,  /* tp_getset */
+    NULL,                              /* tp_base */
+    NULL,                              /* tp_dict */
+    (descrgetfunc)0,    /* tp_descr_get */
+    (descrsetfunc)0,    /* tp_descr_set */
+    0,                 /* tp_dictoffset */
+    (initproc)0,             /* tp_init */
+    (allocfunc)0,           /* tp_alloc */
+    (newfunc)pygio_file_attribute_info_tp_new,               /* tp_new */
+    (freefunc)0,             /* tp_free */
+    (inquiry)0              /* tp_is_gc */
 };
 
+
 PyObject*
 pyg_file_attribute_info_new(const GFileAttributeInfo *info)
 {
@@ -142,6 +145,7 @@ pyg_file_attribute_info_new(const GFileAttributeInfo *info)
     return (PyObject *)self;
 }
 
+
 %%
 init
 if (PyType_Ready(&PyGFileAttributeInfo_Type) < 0) {
diff --git a/gio/gfileinfo.override b/gio/gfileinfo.override
index 9769a65..9012a88 100644
--- a/gio/gfileinfo.override
+++ b/gio/gfileinfo.override
@@ -43,7 +43,7 @@ _wrap_g_file_info_list_attributes(PyGObject *self,
     ret = PyList_New(0);
     n = names;
     while (n && *n) {
-        PyObject *item = PyString_FromString(n[0]);
+        PyObject *item = _PyUnicode_FromString(n[0]);
         PyList_Append(ret, item);
         Py_DECREF(item);
 
diff --git a/gio/gicon.override b/gio/gicon.override
index 247e596..6fbe92f 100644
--- a/gio/gicon.override
+++ b/gio/gicon.override
@@ -177,13 +177,13 @@ _wrap_g_file_icon_tp_repr(PyGObject *self)
     PyObject *result;
 
     if (uri) {
-	representation = g_strdup_printf("<%s at %p: %s>", self->ob_type->tp_name, self, uri);
+	representation = g_strdup_printf("<%s at %p: %s>", Py_TYPE(self)->tp_name, self, uri);
 	g_free(uri);
     }
     else
-	representation = g_strdup_printf("<%s at %p: UNKNOWN URI>", self->ob_type->tp_name, self);
+	representation = g_strdup_printf("<%s at %p: UNKNOWN URI>", Py_TYPE(self)->tp_name, self);
 
-    result = PyString_FromString(representation);
+    result = _PyUnicode_FromString(representation);
     g_free(representation);
     return result;
 }
@@ -202,9 +202,9 @@ _wrap_g_themed_icon_new(PyGObject *self, PyObject *args, PyObject *kwargs)
 				     kwlist, &name, &use_default_fallbacks))
 	return -1;
 
-    if (PyString_Check(name)) {
+    if (_PyUnicode_Check(name)) {
 	pygobject_construct(self,
-			    "name", PyString_AsString(name),
+			    "name", _PyUnicode_AsString(name),
 			    "use-default-fallbacks", use_default_fallbacks, NULL);
 	return 0;
     }
@@ -218,8 +218,8 @@ _wrap_g_themed_icon_new(PyGObject *self, PyObject *args, PyObject *kwargs)
 
 	    for (k = 0; k < length; k++) {
 		PyObject *str = PyTuple_GetItem(tuple, k);
-		if (str && PyString_Check(str))
-		    names[k] = PyString_AsString(str);
+		if (str && _PyUnicode_Check(str))
+		    names[k] = _PyUnicode_AsString(str);
 		else {
 		    Py_DECREF(tuple);
 		    g_free(names);
@@ -257,7 +257,7 @@ _wrap_g_themed_icon_get_names(PyGObject *self)
 
     ret = PyList_New(0);
     while (names && *names) {
-        PyObject *item = PyString_FromString(names[0]);
+        PyObject *item = _PyUnicode_FromString(names[0]);
         PyList_Append(ret, item);
         Py_DECREF(item);
 
@@ -275,7 +275,7 @@ _wrap_g_themed_icon_tp_repr(PyGObject *self)
     GString *representation = g_string_new(NULL);
     PyObject *result;
 
-    g_string_append_printf(representation, "<%s at %p: ", self->ob_type->tp_name, self);
+    g_string_append_printf(representation, "<%s at %p: ", Py_TYPE(self)->tp_name, self);
 
     if (names) {
 	gboolean first_name = TRUE;
@@ -290,7 +290,7 @@ _wrap_g_themed_icon_tp_repr(PyGObject *self)
     }
 
     g_string_append(representation, ">");
-    result = PyString_FromString(representation->str);
+    result = _PyUnicode_FromString(representation->str);
     g_string_free(representation, TRUE);
     return result;
 }
diff --git a/gio/ginputstream.override b/gio/ginputstream.override
index 4a0878c..5cbd494 100644
--- a/gio/ginputstream.override
+++ b/gio/ginputstream.override
@@ -22,6 +22,8 @@
 %%
 headers
 #define BUFSIZE 8192
+#include "glib/pyglib.h"
+#include "glib/pyglib-python-compat.h"
 
 %%
 override g_input_stream_read kwargs
@@ -47,7 +49,7 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
     if (!pygio_check_cancellable(pycancellable, &cancellable))
         return NULL;
 
-    v = PyString_FromStringAndSize((char *)NULL, buffersize);
+    v = _PyBytes_FromStringAndSize((char *)NULL, buffersize);
     if (v == NULL)
         return NULL;
 
@@ -57,7 +59,7 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
             pyg_begin_allow_threads;
             errno = 0;
             chunksize = g_input_stream_read(G_INPUT_STREAM(self->obj),
-                                            PyString_AS_STRING((PyStringObject *)v) + bytesread,
+                                            _PyBytes_AS_STRING(v) + bytesread,
                                             buffersize - bytesread, cancellable,
                                             &error);
             pyg_end_allow_threads;
@@ -81,7 +83,7 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
 
             if (count < 0) {
 		buffersize += BUFSIZE;
-		if (_PyString_Resize(&v, buffersize) < 0)
+		if (_PyBytes_Resize(&v, buffersize) < 0)
 		    return NULL;
 	    }
             else {
@@ -91,7 +93,7 @@ _wrap_g_input_stream_read(PyGObject *self, PyObject *args, PyObject *kwargs)
         }
 
     if (bytesread != buffersize)
-        _PyString_Resize(&v, bytesread);
+        _PyBytes_Resize(&v, bytesread);
 
     return v;
 }
@@ -119,7 +121,7 @@ _wrap_g_input_stream_read_all(PyGObject *self, PyObject *args, PyObject *kwargs)
     if (!pygio_check_cancellable(pycancellable, &cancellable))
         return NULL;
 
-    v = PyString_FromStringAndSize((char *)NULL, buffersize);
+    v = _PyBytes_FromStringAndSize((char *)NULL, buffersize);
     if (v == NULL)
         return NULL;
 
@@ -129,7 +131,7 @@ _wrap_g_input_stream_read_all(PyGObject *self, PyObject *args, PyObject *kwargs)
             pyg_begin_allow_threads;
             errno = 0;
             g_input_stream_read_all(G_INPUT_STREAM(self->obj),
-				    PyString_AS_STRING((PyStringObject *)v) + bytesread,
+				    _PyBytes_AS_STRING(v) + bytesread,
 				    buffersize - bytesread,
 				    &chunksize,
 				    cancellable, &error);
@@ -148,7 +150,7 @@ _wrap_g_input_stream_read_all(PyGObject *self, PyObject *args, PyObject *kwargs)
 
             if (count < 0) {
 		buffersize += BUFSIZE;
-		if (_PyString_Resize(&v, buffersize) < 0)
+		if (_PyBytes_Resize(&v, buffersize) < 0)
 		    return NULL;
 	    }
             else {
@@ -158,9 +160,9 @@ _wrap_g_input_stream_read_all(PyGObject *self, PyObject *args, PyObject *kwargs)
         }
 
     if (bytesread != buffersize)
-        _PyString_Resize(&v, bytesread);
+        _PyBytes_Resize(&v, bytesread);
 
-    return v;
+    return _PyUnicode_FromString(_PyBytes_AsString(v));
 }
 %%
 override g_input_stream_read_async kwargs
@@ -241,10 +243,10 @@ _wrap_g_input_stream_read_finish(PyGObject *self,
         return NULL;
 
     if (bytesread == 0)
-        return PyString_FromString("");
+        return _PyUnicode_FromString("");
 
     notify = pygio_notify_get_attached(result);
-    return PyString_FromStringAndSize(notify->buffer, bytesread);
+    return _PyUnicode_FromStringAndSize(notify->buffer, bytesread);
 }
 %%
 override g_input_stream_close_async kwargs
@@ -320,7 +322,7 @@ _wrap_g_data_input_stream_read_line(PyGObject *self,
     if (pyg_error_check(&error))
         return NULL;
 
-    py_line = PyString_FromStringAndSize(line, length);
+    py_line = _PyBytes_FromStringAndSize(line, length);
     g_free(line);
     return py_line;
 }
@@ -353,7 +355,7 @@ _wrap_g_data_input_stream_read_until(PyGObject *self,
     if (pyg_error_check(&error))
         return NULL;
 
-    py_line = PyString_FromStringAndSize(line, length);
+    py_line = _PyBytes_FromStringAndSize(line, length);
     g_free(line);
     return py_line;
 }
@@ -375,14 +377,17 @@ _wrap_g_memory_input_stream_add_data(PyGObject *self,
         char *copy;
         int length;
 
-        if (!PyString_Check(data)) {
+	if (_PyUnicode_Check(data))
+	    data = _PyBytes_FromString(_PyUnicode_AsString(data));
+
+        if (!_PyBytes_Check(data)) {
             PyErr_SetString(PyExc_TypeError, "data must be a string or None");
             return NULL;
         }
 
-        length = PyString_Size(data);
+        length = _PyBytes_GET_SIZE(data);
         copy = g_malloc(length);
-        memcpy(copy, PyString_AsString(data), length);
+        memcpy(copy, _PyBytes_AsString(data), length);
 
         g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(self->obj),
                                        copy, length, (GDestroyNotify) g_free);
diff --git a/gio/gio.override b/gio/gio.override
index c117fdf..e012f3d 100644
--- a/gio/gio.override
+++ b/gio/gio.override
@@ -29,7 +29,7 @@ headers
 #include <pygobject.h>
 #include <gio/gio.h>
 #include "pygio-utils.h"
-#include "pyglib.h"
+
 
 #define BUFSIZE 8192
 
@@ -338,7 +338,7 @@ _wrap_g_content_type_guess(PyGObject *self, PyObject *args, PyObject *kwargs)
 	ret = Py_BuildValue("zN", type, PyBool_FromLong(result_uncertain));
     
     } else {
-        ret = PyString_FromString(type);
+        ret = _PyUnicode_FromString(type);
     }
 
     g_free(type);
@@ -531,20 +531,20 @@ _wrap_g_mount_tp_repr(PyGObject *self)
     if (name) {
 	if (uuid) {
 	    representation = g_strdup_printf("<%s at %p: %s (%s)>",
-					     self->ob_type->tp_name, self, name, uuid);
+					     Py_TYPE(self)->tp_name, self, name, uuid);
 	}
 	else {
 	    representation = g_strdup_printf("<%s at %p: %s>",
-					     self->ob_type->tp_name, self, name);
+					     Py_TYPE(self)->tp_name, self, name);
 	}
     }
     else
-	representation = g_strdup_printf("<%s at %p: UNKNOWN NAME>", self->ob_type->tp_name, self);
+	representation = g_strdup_printf("<%s at %p: UNKNOWN NAME>", Py_TYPE(self)->tp_name, self);
 
     g_free(name);
     g_free(uuid);
 
-    result = PyString_FromString(representation);
+    result = _PyUnicode_FromString(representation);
     g_free(representation);
     return result;
 }
@@ -560,7 +560,7 @@ _wrap_g_vfs_get_supported_uri_schemes(PyGObject *self)
 
     ret = PyList_New(0);
     while (names && *names) {
-        PyObject *item = PyString_FromString(names[0]);
+        PyObject *item = _PyUnicode_FromString(names[0]);
         PyList_Append(ret, item);
         Py_DECREF(item);
 
@@ -582,7 +582,7 @@ _wrap_g_content_types_get_registered(PyObject *self)
     ret = PyList_New(0);
     for (l = list; l; l = l->next) {
 	char *content_type = l->data;
-	PyObject *string = PyString_FromString(content_type);
+	PyObject *string = _PyUnicode_FromString(content_type);
 	PyList_Append(ret, string);
 	Py_DECREF(string);
 	g_free(content_type);
diff --git a/gio/giomodule.c b/gio/giomodule.c
index 171a06f..01e6ac4 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -23,9 +23,9 @@
 #  include "config.h"
 #endif
 #include <Python.h>
-#include <pyglib.h>
-#include <pygobject.h>
-
+#include "pyglib.h"
+#include "pyglib-python-compat.h"
+#include "pygobject.h"
 #include <gio/gio.h>
 
 #define PYGIO_MAJOR_VERSION PYGOBJECT_MAJOR_VERSION
@@ -34,162 +34,160 @@
 
 /* include any extra headers needed here */
 
-void pygio_register_classes(PyObject *d);
-void pygio_add_constants(PyObject *module, const gchar *strip_prefix);
+void _gio_register_classes(PyObject *d);
+void _gio_add_constants(PyObject *module, const gchar *strip_prefix);
+
+extern PyMethodDef _gio_functions[];
 
-extern PyMethodDef pygio_functions[];
+PYGLIB_MODULE_START(_gio, "gio._gio")
 
-DL_EXPORT(void)
-init_gio(void)
-{
-    PyObject *m, *d;
+    PyObject *d;
     PyObject *tuple;
     PyObject *e;
     /* perform any initialisation required by the library here */
 
-    m = Py_InitModule("gio._gio", pygio_functions);
-    d = PyModule_GetDict(m);
+    d = PyModule_GetDict(module);
 
-    init_pygobject_check(2, 15, 2);
+    pygobject_init(2, 15, 2);
 
-    pygio_register_classes(d);
-    pygio_add_constants(m, "G_IO_");
+    _gio_register_classes(d);
+    _gio_add_constants(module, "G_IO_");
 
-    PyModule_AddStringConstant(m, "ERROR", g_quark_to_string(G_IO_ERROR));
+    PyModule_AddStringConstant(module, "ERROR", g_quark_to_string(G_IO_ERROR));
     e = pyglib_register_exception_for_domain("gio.Error", G_IO_ERROR);
     PyDict_SetItemString(d, "Error", e);
     Py_DECREF(e);
 
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_TYPE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_TYPE",
 			       G_FILE_ATTRIBUTE_STANDARD_TYPE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_IS_HIDDEN",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_IS_HIDDEN",
 			       G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_IS_BACKUP",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_IS_BACKUP",
 			       G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_IS_SYMLINK",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_IS_SYMLINK",
 			       G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL",
 			       G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_NAME",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_NAME",
 			       G_FILE_ATTRIBUTE_STANDARD_NAME);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME",
 			       G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_EDIT_NAME",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_EDIT_NAME",
 			       G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_COPY_NAME",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_COPY_NAME",
 			       G_FILE_ATTRIBUTE_STANDARD_COPY_NAME);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_DESCRIPTION",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_DESCRIPTION",
 			       G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_ICON",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_ICON",
 			       G_FILE_ATTRIBUTE_STANDARD_ICON);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE",
 			       G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE",
 			       G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_SIZE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_SIZE",
 			       G_FILE_ATTRIBUTE_STANDARD_SIZE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET",
 			       G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_TARGET_URI",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_TARGET_URI",
 			       G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_STANDARD_SORT_ORDER",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_STANDARD_SORT_ORDER",
 			       G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ETAG_VALUE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ETAG_VALUE",
 			       G_FILE_ATTRIBUTE_ETAG_VALUE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ID_FILE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ID_FILE",
 			       G_FILE_ATTRIBUTE_ID_FILE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ID_FILESYSTEM",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ID_FILESYSTEM",
 			       G_FILE_ATTRIBUTE_ID_FILESYSTEM);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_READ",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_READ",
 			       G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_WRITE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_WRITE",
 			       G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE",
 			       G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_DELETE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_DELETE",
 			       G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_TRASH",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_TRASH",
 			       G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_ACCESS_CAN_RENAME",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_ACCESS_CAN_RENAME",
 			       G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT",
 			       G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT",
 			       G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT",
 			       G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE",
 			       G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_MOUNTABLE_HAL_UDI",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_MOUNTABLE_HAL_UDI",
 			       G_FILE_ATTRIBUTE_MOUNTABLE_HAL_UDI);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_MODIFIED",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_MODIFIED",
 			       G_FILE_ATTRIBUTE_TIME_MODIFIED);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_MODIFIED_USEC",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_MODIFIED_USEC",
 			       G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_ACCESS",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_ACCESS",
 			       G_FILE_ATTRIBUTE_TIME_ACCESS);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_ACCESS_USEC",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_ACCESS_USEC",
 			       G_FILE_ATTRIBUTE_TIME_ACCESS_USEC);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_CHANGED",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_CHANGED",
 			       G_FILE_ATTRIBUTE_TIME_CHANGED);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_CHANGED_USEC",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_CHANGED_USEC",
 			       G_FILE_ATTRIBUTE_TIME_CHANGED_USEC);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_CREATED",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_CREATED",
 			       G_FILE_ATTRIBUTE_TIME_CREATED);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TIME_CREATED_USEC",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TIME_CREATED_USEC",
 			       G_FILE_ATTRIBUTE_TIME_CREATED_USEC);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_DEVICE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_DEVICE",
 			       G_FILE_ATTRIBUTE_UNIX_DEVICE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_INODE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_INODE",
 			       G_FILE_ATTRIBUTE_UNIX_INODE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_MODE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_MODE",
 			       G_FILE_ATTRIBUTE_UNIX_MODE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_NLINK",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_NLINK",
 			       G_FILE_ATTRIBUTE_UNIX_NLINK);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_UID",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_UID",
 			       G_FILE_ATTRIBUTE_UNIX_UID);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_GID",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_GID",
 			       G_FILE_ATTRIBUTE_UNIX_GID);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_RDEV",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_RDEV",
 			       G_FILE_ATTRIBUTE_UNIX_RDEV);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_BLOCK_SIZE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_BLOCK_SIZE",
 			       G_FILE_ATTRIBUTE_UNIX_BLOCK_SIZE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_BLOCKS",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_BLOCKS",
 			       G_FILE_ATTRIBUTE_UNIX_BLOCKS);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT",
 			       G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_DOS_IS_ARCHIVE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_DOS_IS_ARCHIVE",
 			       G_FILE_ATTRIBUTE_DOS_IS_ARCHIVE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_DOS_IS_SYSTEM",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_DOS_IS_SYSTEM",
 			       G_FILE_ATTRIBUTE_DOS_IS_SYSTEM);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_OWNER_USER",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_OWNER_USER",
 			       G_FILE_ATTRIBUTE_OWNER_USER);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_OWNER_USER_REAL",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_OWNER_USER_REAL",
 			       G_FILE_ATTRIBUTE_OWNER_USER_REAL);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_OWNER_GROUP",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_OWNER_GROUP",
 			       G_FILE_ATTRIBUTE_OWNER_GROUP);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_THUMBNAIL_PATH",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_THUMBNAIL_PATH",
 			       G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_THUMBNAILING_FAILED",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_THUMBNAILING_FAILED",
 			       G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_SIZE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_SIZE",
 			       G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_FREE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_FREE",
 			       G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_TYPE",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_TYPE",
 			       G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_READONLY",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_READONLY",
 			       G_FILE_ATTRIBUTE_FILESYSTEM_READONLY);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW",
 			       G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_GVFS_BACKEND",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_GVFS_BACKEND",
 			       G_FILE_ATTRIBUTE_GVFS_BACKEND);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_SELINUX_CONTEXT",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_SELINUX_CONTEXT",
 			       G_FILE_ATTRIBUTE_SELINUX_CONTEXT);
-    PyModule_AddStringConstant(m, "FILE_ATTRIBUTE_TRASH_ITEM_COUNT",
+    PyModule_AddStringConstant(module, "FILE_ATTRIBUTE_TRASH_ITEM_COUNT",
 			       G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT);
     
-    PyModule_AddStringConstant(m, "ERROR", g_quark_to_string(G_IO_ERROR));
+    PyModule_AddStringConstant(module, "ERROR", g_quark_to_string(G_IO_ERROR));
 
     /* pygio version */
     tuple = Py_BuildValue ("(iii)",
@@ -198,5 +196,4 @@ init_gio(void)
 			   PYGIO_MICRO_VERSION);
     PyDict_SetItemString(d, "pygio_version", tuple); 
     Py_DECREF(tuple);
-}
-
+PYGLIB_MODULE_END
diff --git a/gio/goutputstream.override b/gio/goutputstream.override
index 9e2f8c4..5e6470a 100644
--- a/gio/goutputstream.override
+++ b/gio/goutputstream.override
@@ -51,7 +51,7 @@ _wrap_g_output_stream_write(PyGObject *self,
   if (pyg_error_check(&error))
     return NULL;
       
-  return PyInt_FromLong(written);
+  return _PyLong_FromLong(written);
 }
 %%
 override g_output_stream_write_all kwargs
@@ -85,7 +85,7 @@ _wrap_g_output_stream_write_all(PyGObject *self,
   if (pyg_error_check(&error))
     return NULL;
       
-  return PyInt_FromLong(written);
+  return _PyLong_FromLong(written);
 }
 %%
 override g_output_stream_write_async kwargs
@@ -206,8 +206,8 @@ static PyObject *
 _wrap_g_memory_output_stream_get_data(PyGObject *self)
 {
     GMemoryOutputStream *stream = G_MEMORY_OUTPUT_STREAM(self->obj);
-    return PyString_FromStringAndSize(g_memory_output_stream_get_data(stream),
-				      g_seekable_tell(G_SEEKABLE(stream)));
+    return _PyUnicode_FromStringAndSize(g_memory_output_stream_get_data(stream),
+				        g_seekable_tell(G_SEEKABLE(stream)));
 }
 
 /* GOutputStream.write_all: No ArgType for const-void* */
diff --git a/gio/gvolume.override b/gio/gvolume.override
index 9afe19d..d2a16cb 100644
--- a/gio/gvolume.override
+++ b/gio/gvolume.override
@@ -148,13 +148,13 @@ _wrap_g_volume_tp_repr(PyGObject *self)
     PyObject *result;
 
     if (name) {
-	representation = g_strdup_printf("<%s at %p: %s>", self->ob_type->tp_name, self, name);
+	representation = g_strdup_printf("<%s at %p: %s>", Py_TYPE(self)->tp_name, self, name);
 	g_free(name);
     }
     else
-	representation = g_strdup_printf("<%s at %p: UNKNOWN NAME>", self->ob_type->tp_name, self);
+	representation = g_strdup_printf("<%s at %p: UNKNOWN NAME>", Py_TYPE(self)->tp_name, self);
 
-    result = PyString_FromString(representation);
+    result = _PyUnicode_FromString(representation);
     g_free(representation);
     return result;
 }
diff --git a/gio/pygio-utils.c b/gio/pygio-utils.c
index be41453..f51040c 100644
--- a/gio/pygio-utils.c
+++ b/gio/pygio-utils.c
@@ -116,13 +116,13 @@ pygio_pylist_to_uri_glist(PyObject *pyfile_list)
     len = PySequence_Size(pyfile_list);
     for (i = 0; i < len; i++) {
     item = PySequence_GetItem(pyfile_list, i);
-        if (!PyString_Check(item)) {
+        if (!_PyUnicode_Check(item)) {
             PyErr_SetString(PyExc_TypeError,
                             "files must be strings");
             g_list_free(file_list);
             return NULL;
         }
-        file_list = g_list_prepend(file_list, PyString_AsString(item));
+        file_list = g_list_prepend(file_list, _PyUnicode_AsString(item));
     }
     file_list = g_list_reverse(file_list);
 
@@ -145,7 +145,7 @@ strv_to_pylist (char **strv)
     list = PyList_New (len);
 
     for (i = 0; i < len; i++)
-        PyList_SetItem (list, i, PyString_FromString (strv[i]));
+        PyList_SetItem (list, i, _PyUnicode_FromString (strv[i]));
 
     return list;
 }
@@ -191,7 +191,7 @@ pylist_to_strv (PyObject *list,
             return FALSE;
         }
 
-        if (!PyString_Check (item))
+        if (!_PyUnicode_Check (item))
         {
             Py_DECREF (item);
             g_strfreev (ret);
@@ -199,7 +199,7 @@ pylist_to_strv (PyObject *list,
             return FALSE;
         }
 
-        ret[i] = g_strdup (PyString_AsString (item));
+        ret[i] = g_strdup (_PyUnicode_AsString (item));
         Py_DECREF (item);
     }
 
diff --git a/gio/pygio-utils.h b/gio/pygio-utils.h
index 76bfde3..bd40521 100644
--- a/gio/pygio-utils.h
+++ b/gio/pygio-utils.h
@@ -27,6 +27,7 @@
 #include <Python.h>
 #include <pygobject.h>
 #include <gio/gio.h>
+#include "pyglib-python-compat.h"
 
 extern PyTypeObject PyGCancellable_Type;
 extern PyTypeObject PyGAppLaunchContext_Type;
diff --git a/gio/unix.override b/gio/unix.override
index bdf710e..7bab55a 100644
--- a/gio/unix.override
+++ b/gio/unix.override
@@ -22,6 +22,9 @@
 %%
 headers
 #define NO_IMPORT_PYGOBJECT
+#include "pyglib.h"
+#include "pyglib-python-compat.h"
+
 #include <pygobject.h>
 #include <gio/gdesktopappinfo.h>
 #include <gio/gunixinputstream.h>
diff --git a/gio/unixmodule.c b/gio/unixmodule.c
index 7a49856..cd4595b 100644
--- a/gio/unixmodule.c
+++ b/gio/unixmodule.c
@@ -23,30 +23,29 @@
 #  include "config.h"
 #endif
 #include <Python.h>
-#include <pygobject.h>
+
+#include "pyglib.h"
+#include "pyglib-python-compat.h"
+#include "pygobject.h"
 
 #include <gio/gio.h>
 
 /* include any extra headers needed here */
 
-void pyunix_register_classes(PyObject *d);
-void pyunix_add_constants(PyObject *module, const gchar *strip_prefix);
+void _unix_register_classes(PyObject *d);
+void _unix_add_constants(PyObject *module, const gchar *strip_prefix);
 
-extern PyMethodDef pyunix_functions[];
+extern PyMethodDef _unix_functions[];
 
-DL_EXPORT(void)
-initunix(void)
-{
-    PyObject *m, *d;
+PYGLIB_MODULE_START(_unix, "gio._unix")
+    PyObject *d;
 
     /* perform any initialisation required by the library here */
 
-    m = Py_InitModule("gio.unix", pyunix_functions);
-    d = PyModule_GetDict(m);
-
-    init_pygobject();
+    d = PyModule_GetDict(module);
 
-    pyunix_register_classes(d);
+    pygobject_init(2, 15, 2);
 
-}
+    _unix_register_classes(d);
 
+PYGLIB_MODULE_END
