Pyrex - a Language for Writing Python Extension Modules (original) (raw)

Brief DescriptionPyrex lets you write code that mixes Python and C data types any way you want, and compiles it into a C extension for Python. Documentation About Pyrex Language Overview FAQ Contributed by Users Download Pyrex compiler and documentation <Pyrex-0.9.9.tar.gz> (255272 bytes, 2010-04-12) Test suite and testing framework <Pyrex-Tests-0.9.9.tar.gz> (447472 bytes, 2010-04-12) Note: Currently the testing framework will only work out of the box on MacOS X or Linux, but should be adaptable to other unices with a little work.Release Notes for Version 0.9.9 Changes Mercurial Repository and Updates Previous ReleasesPyrex requires Python 2.3 or later, both to run the Pyrex compiler and to use the generated extension modules. News Version 0.9.9Some features for interfacing with C++ code have been introduced, a few things have been changed, and some bugs have been fixed. See the Release Notes and CHANGES for details.Old News Patches WARNING:I have not reviewed or tested these patches - use them at your own risk. Sam Rushing has submitted a patch to Pyrex 0.9.3.1 which adds some conditional compilationfacilities. Old Patches Lenard Lindstrom contributed some patches to Pyrex 0.9.3.1 to improve the C++ compatibility of the generated code. Since 0.9.4 these should no longer be necessary. PackagesThese packages are maintained by others, so they may not be up to date with the latest version. WindowsWindowsContributed by Samuel Thibault Related Tools Pyrex Builder XA mini-IDE for building Pyrex projects on MacOSX, by Nik Molnar. Mailing List IRC Channel irc.freenode.net #pyrexI don't normally use IRC myself, but you may find someone there who's able to help you. Author Greg Ewing (greg.ewing@canterbury.ac.nz) Example Pyrex modules ## Calculate prime numbers#def primes(int kmax): cdef int n, k, i cdef int p[1000] result = [] if kmax > 1000: kmax = 1000 k = 0 n = 2 while k < kmax: i = 0 while i < k and n % p[i] <> 0: i = i + 1 if i == k: p[k] = n k = k + 1 result.append(n) n = n + 1 return result ## Defining an extension type#cdef class Spam: cdef int amount def __cinit__(self): self.amount = 0 def get_amount(self): return self.amount def set_amount(self, new_amount): self.amount = new_amount def describe(self): print self.amount, "tons of spam!"