O'Reilly logo

Python High Performance Programming by Gabriele Lanaro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sharing declarations

When writing your Cython modules, you may want to encapsulate generic functions and types in a separate file. Cython allows you to reuse those components with the cimport statement by writing a definition file.

Let's say we have a module with the functions max and min, and we want to reuse those functions in multiple Cython programs. If we simply write a .pyx file—also called implementation file—the functions declared are confined in the same module.

Note

Definition files are also used to interface Cython with an external C code. The idea is to copy the types and function prototypes in the definition file and leave the implementation to the external C code.

To share those functions we need to write a definition file, with a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required