Creating a Python package for a C extension-only module which is pre-built

Viewed 1035

I want to create a package for a project that does not contain any .py source files, but is completely implemented as a Python C extension (resulting in an .so). Additionally, assume that the .so is already built by a separate build process (say CMake).

I know that setuptools/distutils minimally requires a directory structure:

  • mymodule
    • __init__.py

But what I really want is for mymodule to be provided by a C extension (say mymodule.so) such that after installing the package, import mymodule has the same effect as directly importing mymodule.so.

I know that I could have this kind of directory structure:

  • mymodule
    • __init__.py
    • mymodule_native.so

and have __init__.py be:

from mymodule_native import *

This kind of works, but an object A imported from mymodule will actually look like mymodule.mymodule_native.A.

Is there a more direct way?

1 Answers
Related