cython-wheel-hello-world aims to demonstrate a minimal correct project structure and wheel file build procedure for cython projects. Python packaging has evolved with PEP 517 and PEP 518 (etc.) and the introduction of the many packaging tools listed by the Python Packaging Authority, and meanwhile there is a lot of outdated or incorrect guidance online.
This small cython project generates wheel files using setuptools (including setup.py to configure the cython extensions), pyproject.toml (to configure a virtual env for building the wheel file), MANIFEST.in (so the compiled cython code is packaged with the wheel file), and using either build or cibuildwheel to build the wheel files.
The wheel file for this project can be built using build:
python -m build
Or alternatively, using cibuildwheel (note: if using Windows or Mac OS, docker is required if the platform option is set to linux
):
cibuildwheel --platform=linux --output-dir=dist
The wheel file can then be installed:
pip install dist/cython_wheel_hello_world[versioning_info].whl
Finally, the code can be run:
> from cython_wheel_hello_world import hello_world
> hello_world()
Hello, world!
- Juan José García Ripoll's project cython_example provides a more complete example.
- PyPa's guide for packing modules that include binary extensions