Pyrex is a
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
for creating
Python modules. Its syntax is very close to Python and it makes it easy for Python programmers to write non-Python supporting code for interfacing modules in a language which is as close to Python as possible.
Python itself only provides a
C API
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
to write extension modules, which allows writing of
functions and
datatype
In computer science and computer programming, a data type (or simply type) is a collection or grouping of data values, usually specified by a set of possible values, a set of allowed operations on these values, and/or a representation of these ...
s in C. These can then be accessed from Python. It is possible to wrap the functions and datatypes of existing C
libraries
A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
as Python objects and therefore make them available to Python.
Pyrex allows the user to write extension modules in a Python-like language which may directly access the external C code. The similarity of Pyrex's syntax to Python's makes it easy to write Python modules, but there are some functional limitations. The programmer must specify the name of C-header files,
enumeration
An enumeration is a complete, ordered listing of all the items in a collection. The term is commonly used in mathematics and computer science to refer to a listing of all of the element (mathematics), elements of a Set (mathematics), set. The pre ...
s, datatypes and functions needing to be accessed in the module, then they can be used as if they were Python objects. The Pyrex compiler will generate the necessary glue code automatically and compile the Pyrex code into a working Python module.
There are tools like
SWIG or Python's foreign function library ''ctypes'' which can be used for this task without requiring much additional code, but this is limited to making an external library available in Python code.
If adjustments to the API are needed, glue code must again be written manually.
See also
*
Cython
References
External links
*
{{Compu-prog-stub
Free and open source compilers
Python (programming language)