Limited API & free-threaded build

Now that 3.13.0 is out, I’m trying to do more than simply build and run unit tests with free threading enabled. While trying to construct an environment approximating what I typically use with 3.12 (mostly Jupyter, Flask and their minion libraries), I encountered this #error in Python.h when trying to build a dependency of Jupyter, argon2-cffi:

#  error "The limited API is not currently supported in the free-threaded build"

I understand that the free-threaded build is still experimental. I’m curious to know if this restriction is likely to be lifted before 3.14 is released, or if I’m just going to have to be patient. I suspect the absence of Jupyter will make it difficult to test many third-party scientific and numerical packages in the free-threaded environment.

3 Likes

I believe the plan is to try to lift it for 3.14.

The error is probably misleading though… It’s more that the “stable ABI” isn’t supported (so you can’t build extension modules compatible with more than one version). An extension module that uses functions in the limited API should generally work.

So really ask you need to do is disable the Py_LIMITED_API define for argon2-cffi and it’ll (most likely) work fine.

FWIW we talk about this in the porting guide here: Porting Python Packages to Support Free-Threading - py-free-threading

PRs welcome to make this info more discoverable!

3 Likes

Tangential to what you said, maybe, but one can use ipykernel 7.0.0 (unreleased, from git) with 3.13+freethreaded already. That makes it possible to run the kernel freethreaded while jupyter/jupyterlab itself runs on a regular release of Python 3.13. Then you exercise the code interesting to you - presumably - on 3.13t.

(Use the various ways to run ipykernel from a specific virtual environment to enable this, the main way in jupyter probably being to install a kernelspec, but other methods exist too.)

3 Likes

I went ahead and created two pull requests to hopefully clarify the state of things with respect to both Jupyter and the limited API.