Source

pypy.org / compat.html

<!DOCTYPE html>
<html>
<head>
	<title>PyPy :: Python compatibility</title>
	<meta http-equiv="content-language" content="en" />
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="author" content="PyPy Team" />
	<meta name="description" content="PyPy" />
	<meta name="copyright" content="MIT" />
	<meta name="document-rating" content="general" />
	<link rel="stylesheet" type="text/css" media="screen" title="default" href="css/site.css" />
	<link rel="alternate" type="application/rss+xml" title="RSS Feed for PyPy" href="http://feeds.feedburner.com/PyPyStatusBlog" />
  <link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.14.custom.css" />
	<script type="text/javascript" src="http://use.typekit.com/hdt8sni.js"></script>
	<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
  <script type="text/javascript" src="js/detect.js"></script>
  <script type="text/javascript" src="js/script2.js?bust=1"></script>
</head>
<body>
<script type="text/javascript">
	var _gaq = [['_setAccount', 'UA-7778406-3'], ['_trackPageview']];
	if (document.location.protocol !== 'file:') {
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
		})();
	}
</script>
<div id="body-outer"><div id="body-inner"><div id="body" class="clearfix">
<div id="header">
	<div id="menu-follow">
		<div><a href="http://search.twitter.com/search?q=%23pypy" title="Follow the conversation on Twitter"><img src="http://static.ampify.it/icon.twitter.gif" alt="Follow the conversation on Twitter" width="14px" height="14px" /></a></div>
    <div><a href="https://bitbucket.org/pypy/pypy"><img src="http://www.selenic.com/hg-logo/logo-droplets-25.png" width="14px" height="14px" /></a></div>
		<div><a href="http://feeds.feedburner.com/PyPyStatusBlog" title="Subscribe to the RSS Feed"><img src="http://static.ampify.it/icon.rss.png" alt="Subscribe to the RSS Feed" width="14px" height="14px" /></a></div>
	</div>
	<div id="logo"><a href="http://pypy.org"><img src="image/pypy-logo.png" alt="PyPy" height="110px" /></a></div>
	<hr class="clear-left" />
	<div id="menu-sub"><a href="index.html">Home</a><span class="menu-sub-sep"> | </span><a href="features.html">Features</a><span class="menu-sub-sep"> | </span><a href="download.html">Download</a><span class="menu-sub-sep"> | </span><a href="compat.html">Compatibility</a><span class="menu-sub-sep"> | </span><a href="performance.html">Performance</a><span class="menu-sub-sep"> | </span><a href="http://doc.pypy.org">Dev Documentation</a><span class="menu-sub-sep"> | </span><a href="http://morepypy.blogspot.com">Blog</a><span class="menu-sub-sep"> | </span><a href="people.html">People</a><span class="menu-sub-sep"> | </span><a href="contact.html">Contact</a><span class="menu-sub-sep"> | </span><a href="py3donate.html">Py3k donations</a><span class="menu-sub-sep"> | </span><a href="numpydonate.html">NumPy donations</a><span class="menu-sub-sep"> | </span><a href="tmdonate.html">STM/AME donations</a></div>
	<hr class="clear" />
</div>
<div id="content">
<div>
<div id="main">
<h1 class="title">Python compatibility</h1>
<p>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 <a class="reference external" href="http://docs.python.org/library/">standard library modules</a>; details below.</p>
<p>PyPy has <strong>alpha/beta-level</strong> support for the <a class="reference external" href="http://docs.python.org/c-api/">CPython C API</a>, 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 <a class="reference external" href="https://bitbucket.org/pypy/compatibility/wiki/Home">Compatibility Wiki</a>.</p>
<p>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.</p>
<p>Standard library modules supported by PyPy, in alphabetical order:</p>
<ul class="simple">
<li><tt class="docutils literal">__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</tt></li>
</ul>
<p>Supported, but written in pure-python:</p>
<ul class="simple">
<li><tt class="docutils literal">cPickle, _csv, ctypes, datetime, dbm, _functools, grp, pwd, readline, resource, sqlite3, syslog, tputil</tt></li>
</ul>
<p>All modules that are pure python in CPython of course work.</p>
<p>Python libraries known to work under PyPy (the list is not exhaustive):</p>
<ul class="simple">
<li>ctypes</li>
<li>django</li>
<li>sqlalchemy</li>
<li>flask</li>
<li>twisted (without ssl support)</li>
<li>pylons</li>
<li>divmod's nevow</li>
<li>pyglet</li>
</ul>
<p>Known differences that are not going to be fixed:</p>
<ul>
<li><p class="first">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:</p>
<div class="syntax python"><pre><span class="nb">open</span><span class="p">(</span><span class="s">&quot;filename&quot;</span><span class="p">,</span> <span class="s">&quot;w&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;stuff&quot;</span><span class="p">)</span><br/></pre></div>
<p>The proper fix is</p>
<div class="syntax python"><pre><span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s">&quot;filename&quot;</span><span class="p">,</span> <span class="s">&quot;w&quot;</span><span class="p">)</span><br/><span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;stuff&quot;</span><span class="p">)</span><br/><span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span><br/></pre></div>
<p>or using the <tt class="docutils literal">with</tt> keyword</p>
<div class="syntax python"><pre><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s">&quot;filename&quot;</span><span class="p">,</span> <span class="s">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span><br/>    <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;stuff&quot;</span><span class="p">)</span><br/></pre></div>
</li>
<li><p class="first">For the same reason, some functions and attributes of the <tt class="docutils literal">gc</tt> module
behave in a slightly different way: for example, <tt class="docutils literal">gc.enable</tt> and
<tt class="docutils literal">gc.disable</tt> are supported, but instead of enabling and disabling the GC,
they just enable and disable the execution of finalizers.  Also,
<tt class="docutils literal">gc.garbage</tt> always returns an empty list.</p>
</li>
<li><p class="first">You can't add a <tt class="docutils literal">__del__</tt> 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.</p>
</li>
<li><p class="first">You can't store non-string keys in type objects. Example</p>
<div class="syntax python"><pre><span class="k">class</span> <span class="nc">A</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span><br/>    <span class="nb">locals</span><span class="p">()[</span><span class="mi">42</span><span class="p">]</span> <span class="o">=</span> <span class="mi">3</span><br/></pre></div>
<p>won't work.</p>
</li>
</ul>
<p>A more complete list is available at <a class="reference external" href="http://pypy.readthedocs.org/en/latest/cpython_differences.html">our dev site</a>.</p>
</div>
<div id="sidebar">
</div>
</div>
</div>
</div></div></div>
</body>
</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.