Skip to content
Snippets Groups Projects
compat.html 9.06 KiB
Newer Older
  • Learn to ignore specific revisions
  • <!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">
    
    Armin Rigo's avatar
    Armin Rigo committed
        <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>
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    		<div><a href="http://feeds.feedburner.com/PyPyStatusBlog" title="Subscribe to the RSS Feed"><img src="http://feedburner.google.com/fb/lib/images/icons/feed-icon-12x12-orange.gif" alt="Subscribe to the RSS Feed" width="14px" height="14px" /></a></div>
    
    Armin Rigo's avatar
    Armin Rigo committed
          <div><a href="http://flattr.com/thing/1191749/PyPy" target="_blank">
          <img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" /></a></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>
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    <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
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    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>
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    <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
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    2.0 beta2
    
    Antonio Cuni's avatar
    Antonio Cuni committed
    release this feature is not yet complete. Many libraries will require
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    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>
    
    Alex Gaynor's avatar
    Alex Gaynor committed
    <p>C extensions need to be recompiled for PyPy in order to work. Depending on
    
    Antonio Cuni's avatar
    Antonio Cuni committed
    your build system, it might work out of the box or will be slightly harder.</p>
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    <p>Standard library modules supported by PyPy. Note that large parts of python
    library are implemented in pure python, so they don't have to be listed
    there. Please just check if it imports. If it imports, it should work.</p>
    
    Armin Rigo's avatar
    Armin Rigo committed
    <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>
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    <p>Python libraries known to work under PyPy (the list is not exhaustive).
    A community maintained <a class="reference external" href="https://bitbucket.org/pypy/compatibility/wiki/Home">compatibility wiki</a> is hosted on bitbucket:</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>
    
    Armin Rigo's avatar
    Armin Rigo committed
    <p>Known differences that are not going to be fixed:</p>
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    <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
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    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>
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    <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>
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    <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>
    
    Armin Rigo's avatar
    Armin Rigo committed
    <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><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>
    
    Armin Rigo's avatar
    Armin Rigo committed
    <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>