Python gi webkit2

I’m trying to add a python package that among other things needs webview, which in turn needs webkit2. I’d like to use it with GTK, but:

$ python
Python 3.11.5 (main, Aug 24 2023, 12:23:19) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import webview.platforms.gtk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/zk13adkl37daamv9mnkrz5bi76dc9zpz-python3-3.11.5-env/lib/python3.11/site-packages/webview/platforms/", line 24, in <module>
    gi.require_version('WebKit2', '4.0')
  File "/nix/store/zk13adkl37daamv9mnkrz5bi76dc9zpz-python3-3.11.5-env/lib/python3.11/site-packages/gi/", line 126, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace WebKit2 not available

How do I make this available?

You need a path to a typelib from webkitgtk package on GI_TYPELIB_PATH, see the GNOME section of Nixpkgs manual.

Thanks @jtojnar. Looking at the page you linked, am I correct that this use case (i.e. a python library) falls under this section:

I am packaging a project that cannot be wrapped, like a library or GNOME Shell extension.

and, if so, does that mean that python executable needs to be wrapped?

Yes, that is correct.

Well, you could also modify the typelib path directly in the module but I would not recommend it unless there is no other choice, since it is a global change that will affect all other libraries loaded by the process.