{{{ #!python class PsycoMiddleware(object): """ This middleware enables the psyco extension module which can massively speed up the execution of any Python code. """ def process_request(self, request): try: import psyco psyco.profile() except ImportError: pass return None }}} Note that this should only be used on 32bit systems. See http://www.alrond.com/en/2007/jan/25/performance-test-of-6-leading-frameworks . One possible way to determine this automatically: {{{ #!python from platform import architecture if architecture()[0] != '32bit': raise Exception("Don't use this on non-32-bit platforms") class PsycoMiddleware(object): """ This middleware enables the psyco extension module which can massively speed up the execution of any Python code. """ def process_request(self, request): try: import psyco psyco.profile() except ImportError: pass return None }}}