[Distutils] cffi & Py_LIMITED_API

Nick Coghlan ncoghlan at gmail.com
Sat Aug 20 23:31:29 EDT 2016

On 21 August 2016 at 10:32, Daniel Holth <dholth at gmail.com> wrote:
> Coded up in https://bitbucket.org/pypa/wheel/pull-requests/69 and
> https://github.com/pypa/pip/pull/3922 and supported in setuptools 26.
> It's a multi-step process, unfortunately, but if you do it correctly then
> you should need a lot fewer wheels:
> 0. Use only the functions from the limited api, for example, by using cffi
> to generate your C extensions. #define Py_LIMITED_API to the desired value.
> Python 3.3 is a good minimum, adding some useful functions forgotten in
> Python 3.2's limited api.
> 1. In setup.py, specify Extension(..., py_limited_api=True) to use .abi3.so
> filenames on your C extensions
> 2. In setup.cfg, specify [bdist_wheel] py_limited_api=cp32 # or greater,
> tagging the wheel for compatibility with that version of CPython, or later.
> This argument is ignored outside of CPython 3.
> 3. A new enough version of pip recognizes the wheel tag
> Your extension uses the limited API, setuptools' Extension() changes the
> filename so that more than just the exact version of Python can find it,
> wheel adds a cp33-abi3-manylinux1_x86 tag, pip finds it, and you no longer
> have to compile new wheels just because a new version of CPython came out.

Very nice! Would you have the time to draft some initial additions to
https://packaging.python.org/extensions/ to help us point folks
towards how to do this? (And why they'd want to - i.e. not needing to
rebuild their extension modules for each new release of CPython)


P.S. No worries if not - if nobody else beats me to it, I should be
able to take a look at updating that page sometime after 3.6b1 next

Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Distutils-SIG mailing list