# Tools for Accelerating Python

- Canonical URL: https://amund.blog/archive-tools-for-accelerating-python/
- Author: Amund Tveit (https://amund.blog/about/)
- Published: 2008-11-29
- Tags: Python, Performance, Compilers
- Original Source: amundblog.blogspot.com (https://amundblog.blogspot.com/2008/11/tools-for-accelerating-python.html)

---

If you need to speed up your Python program there are several possible approaches, with varying degrees of effort required. Here is a (likely incomplete) overview from late 2008:

## 1. Rewrite or Parallelize Your Python Code

Optimize, tune, or replace algorithms — or parallelize execution using:

- **Hadoop or Disco** — Open-source implementations of [MapReduce](http://labs.google.com/papers/mapreduce.html)
- **Parallel Python**
- **Message Passing Interface (MPI)** — Frequently used for numerical programming
- **Bulk Synchronous Parallel (BSP)**
- **RPyC** — RPC for distributed and parallel programming
- **Twisted** — Networking libraries for distributed/parallel programming
- **Profiling Tools** — Python standard `profile` / `cProfile`
- **Threading or [Microthreads (Stackless)](/archive-stackless-python-microsimulation/)**

## 2. Use a Tool That Speeds Up Code Mostly Unchanged

- **Psyco** — Just-in-time compiler (probably the easiest first approach to try)
- **Pyrex** — Write and compile Python with C-style data structures
- **Cython** — Compiling Python-like code with optional static types to C extensions
- **PyJS** — Compile a large subset of Python to JavaScript (more relevant for client-side Ajax than server-side compute)
- **RPython** — Compile a restricted subset of Python to native code (part of the PyPy project)
- **PyStream / GPULib** — GPU acceleration libraries for Python
- **Shedskin** — Compile a large subset of Python to C++ ([benchmark showing 196× math speedup](http://ianozsvald.com/2008/11/17/making-python-math-196-faster-with-shedskin/))

## 3. Replace Parts of Python with Another Language

- **SWIG (Simplified Wrapper and Interface Generator)** — Call C/C++ from Python
- **F2PY (Fortran to Python Interface Generator)** — Call Fortran from Python
- **llvm-py** — Generate and compile directly to native machine code via LLVM
- **CorePy** — Write assembly code directly in Python
- **SciPy Weave / PyInline** — Inline C/C++ snippets inside Python
- **Boost.Python** — Interoperability between C++ and Python
- **Cinpy** — Blend C code with Python using `ctypes` and runtime compilation via `tcc`
