Source / source / compat.txt

layout: page
title: Python compatibility

PyPy implements the Python language version 2.7.2. 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/beta-level** support for the `CPython C API`_, however, as of 1.9
release this feature is not yet complete. Many libraries will require
a bit of effort to work, but there are known success stories. Check out
PyPy blog for updates, as well as the `Compatibility Wiki`__.

.. __:

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.

Standard library modules supported by PyPy, in alphabetical order:

* ``__builtin__, __pypy__, _ast, _bisect, _codecs, _collections, _ffi, _hashlib, _io, _locale, _lsprof, _md5, _minimal_curses, _multiprocessing, _random, _rawffi, _sha, _socket, _sre, _ssl, _warnings, _weakref, _winreg, array, binascii, bz2, cStringIO, clr, cmath, cpyext, crypt, errno, exceptions, fcntl, gc, imp, itertools, marshal, math, mmap, operator, oracle, parser, posix, pyexpat, select, signal, struct, symbol, sys, termios, thread, time, token, unicodedata, zipimport, zlib``

Supported, but written in pure-python:

* ``cPickle, _csv, ctypes, datetime, dbm, _functools, grp, pwd, readline, resource, sqlite3, syslog, tputil``

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

* sqlalchemy

* flask

* twisted (without ssl support)

* pylons

* divmod's nevow

* pyglet

Known differences 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:

  .. syntax:: python

    open("filename", "w").write("stuff")

  The proper fix is

  .. syntax:: python

    f = open("filename", "w")

  or using the ``with`` keyword

  .. syntax:: python

    with open("filename", "w") as f:

* For the same reason, some functions and attributes of the ``gc`` module
  behave in a slightly different way: for example, ``gc.enable`` and
  ``gc.disable`` are supported, but instead of enabling and disabling the GC,
  they just enable and disable the execution of finalizers.  Also,
  ``gc.garbage`` always returns an empty list.

* You can't add a ``__del__`` method to an existing class; it
  must be present in the class since the beginning, or else it
  will not be automatically called when instances are freed.

* You can't store non-string keys in type objects. Example

  .. syntax:: python

    class A(object):
        locals()[42] = 3

  won't work.

A more complete list is available at `our dev site`_.

.. _`CPython C API`:
.. _`standard library modules`:
.. _`our dev site`: