Python compatibility
PyPy implements the Python language version 2.5. It supports all of the core language, passing Python test suite (with minor modifications that were already accepted in the main python in newer versions). It supports most of the commonly used Python standard library modules; details below.
PyPy has alpha-level support for the CPython C API, however, as of 1.3 release this feature is not yet complete. Most libraries will require a bit of effort to work, but there are known success stories. Check out PyPy blog for updates.
C extensions need to be recompiled for PyPy in order to work. Depending on your build system, it might work out of the box or will be slightly harder. In order to instruct pypy to load a CPython extension (compiled with supplied Python.h), run following line:
import cpyext
before importing any extensions. You can put this line in your PYTHONSTARTUP file if you want this to be enabled permanently.
Standard library modules supported by PyPy, in alphabetical order:
- __builtin__ __pypy__ _codecs _lsprof _minimal_curses _random _rawffi _socket _sre _weakref bz2 cStringIO crypt errno exceptions fcntl gc itertools marshal math md5 mmap operator parser posix pyexpat select sha signal struct symbol sys termios thread time token unicodedata zipimport zlib
Supported, but written in pure-python:
- array binascii cPickle cmath collections ctypes datetime functools grp md5 pwd pyexpat sha sqlite3 syslog
All modules that are pure python in CPython of course work.
Python libraries known to work under PyPy (the list is not exhaustive):
- ctypes
- django (without any DB but sqlite)
- twisted (without ssl support)
- pylons
- divmod's nevow
- pyglet
Known differencies that are not going to be fixed:
PyPy does not support refcounting semantics. The following code won't fill the file immediately, but only after a certain period of time, when the GC does a collection:
open("filename", "w").write("stuff")
The proper fix is
f = open("filename", "w")
f.write("stuff")
f.close()or using the with keyword
with open("filename", "w") as f:
f.write("stuff")We don't support certain attributes that were decided to be implementation-dependent. For example, gc.get_referrers does not exist. Others may have different behavior; for example, gc.enable and gc.disable are supported, but they don't enable and disable the GC, but instead just enable and disable the running of finalizers.
You can't attach a __del__ method to a class after its creation.
You can't store non-string keys in type objects. Example
class A(object):
locals()[42] = 3won't work.
A more complete list is available at our dev site.

