TJB
TJB

Reputation: 4163

How to make a Cython module only meant to be cimport'ed by other Cython modules

I would like to write a Cython module that is only intended to be used by other Cython modules. So it will only contain cdef's (no def or cpdef). I have looked and looked, and found similar topics, but not exactly this one. Could someone please give a brief example? Many thanks!

Upvotes: 0

Views: 246

Answers (1)

Pierre de Buyl
Pierre de Buyl

Reputation: 7293

To cimport a module, you need a .pxd file. There, only cdef level declarations can be present.

For the successful import of the module, the .pxd file must be found in the Python path as a .py would be for a Python module.

To distribute the module, the .pxd file must be included in the package_data argument of setup.py.

It is not easy to find good resources about this on internet and few projects actually provide pxd files. Cython itself bundles a number of them and those are of course importable without specific settings (libc and numpy are there, for instance).

Upvotes: 1

Related Questions