If you feel "the need for speed", you may be interested in Psyco. Psyco is a Specializing Compiler not unlike Java's JIT.   You write Python functions as you normally would, but for those that you want to accelerate, you pass the function to Psyco.   Psyco applies its magic and returns another function reference you can use in lieu of the original.   You may see speed increases of 2x, 3x, occasionally 100x, and of course, some functions actually run slower.  

Psyco is 'nicer' than SWIG or Pyrex because you have less to do to get it running, and there is the potential for the JIT-like optimizations to actually be faster than typical compiled code.   ...but you pay a slight penalty for the run-time compilation.  

Target inner loops and stay with vanilla code.   Psyco is in development, so some language features are not fully supported, and Psyco may throw an exception when a variable's data type changes mid-execution.   And the current version of Psyco only supports x86 processors.  

Instructions for Python 2.2.x on Windows

These minimalist are instructions. See for more information.

Extract the contents of this zip file to 'site-packages' in 'Lib' in your Python directory. (This .zip is only good for Windows Python v2.2.x. Source for version 0.4.0 is available here.)

Profile your code and select opportunities. Then...

For those functions you want to run under Psyco, add a line that runs them thru Psyco, as in...

You may now use the psyco'd function in place of the original.

Test with timing routines like...

Computational functions achieve the greatest acceleration, and those functions heavy with list and dictionary processing achieve less.   (Off-topic: dictionaries are fast and can be quicker than lists in many situations.)


If you are not sure Psyco is available on the target machine, consider the following construct.

More information is available at:
      Psyco home page:
      Armin's comments: psyco-ISSUES.txt
      2002 European Python and Zope Conference
      2002 O'Reilly Open Source Convention

Another alternative is Pyrex.