Packaging Python C Extensions
Once we have a working C extension module, we might want to let other people get it and use it. We need to prepare some information about the module and then prepare it to be distributed.
We will use PEP517, the current standard to package and distribute Python modules.
Information about the module
We need to create a few files, starting by
specifies the tools used for building the package:
[build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta"
setup.cfg with information about the module:
[metadata] name = demo version = 0.1 author = John Smith author_email = email@example.com description = demo is a simple C extension long_description = file: README.md long_description_content_type = text/markdown classifiers = Programming Language :: Python :: 3 License :: OSI Approved :: GPLv3 Operating System :: OS Independent
README.md that is mentioned above:
# Demo The demo module
setup.py with information about the extension, like
C language source files and C libraries that are needed:
from distutils.core import setup, Extension module = Extension('demo', sources = ['demo.c'], libraries = ['asound']) setup(ext_modules=[module])
to make two distribution files: A source distribution 
demo-0.1.tar.gz that requires compiling on the target machine to create the module, and
a wheel 
demo-0.1-cp39-cp39-linux_i686.whl, which is a binary distribution that does not required a compiler in the target machine.
This is the command to run
build and the main steps of the output:
$ env/bin/python -m build * Getting dependencies for sdist... * Building sdist... * Building wheel from sdist * Getting dependencies for wheel... * Building wheel... Successfully built demo-0.1.tar.gz and demo-0.1-cp39-cp39-linux_i686.whl
Click here to see the full output.