My first Pyrex demo at the BayPIGgies group. This is a minimal example demonstrating that Pyrex can run ordinary Python and also call C functions.

The source file is Pyrex source, which looks almost like Python.
simple.pyx:

print "hello pyrex"

cdef extern void c_func()
c_func()
Here's the C function that my Pyrex program calls.
simple_clib.c:
void c_func()
{
  printf("a c function\n");
}
setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext
setup(name="simple",
      ext_modules=[
        Extension("simple",["simple.pyx"],
                  extra_objects=['simple_clib.o']
                 ),
        ],  
      cmdclass={'build_ext':build_ext})

I built simple_clib.o with "gcc -c simple_clib.c" (maybe distutils could have done that too?) and built the module with "python setup.py build --inplace". That last flag puts the result, simple.so, in the current directory instead of in the build/ tree somewhere.

Since my code was in the top level of the simple.pyx code, it runs upon import:

% python -c "import simple"
hello pyrex
a c function

Powered by Zope