Jump to content

Pyrex (programming language)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Allefant (talk | contribs) at 17:31, 29 November 2005 (Created a new page about the Pyrex compiler). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Pyrex
Developer(s)Greg Ewing
Stable release
0.9.3.1 / September 16, 2005
Operating systemCross-platform
TypeProgramming language
Websitewww.cosc.canterbury.ac.nz/~greg/python/Pyrex

Pyrex is a language developed to aid in creating Python modules. Python provides a C API to write extension modules, which allows you to write functions and datatypes in C, which can then be accessed from Python. That way, it also is possible to wrap the functions and datatypes of existing C libraries as Python objects, and therefore make them available to Python. This process is rather lengthy and non-trivial though.

There are tools like SWIG which help to automate the process, but this is limited to making an external library available in Python code. If adjustements to the API are needed, it again is required to manually write glue code. This is where Pyrex sets in. It allows to write extension modules in a Python like language, which may directly access the external C code.

This makes it easy to write Python modules, because you don't have to learn another language like C or C++, and also don't need to write any glue code. All you need to do is specify the name of C header files, enumerations, datatypes, and functions you need to access in your module, and then simply use them as if they were Python objects. The pyrex compiler will generate all the necessary glue code automatically, and compile the pyrex code into a working Python module.