Skip to content
Snippets Groups Projects
compat.html 10.7 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>
    </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>
    
    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>
    
    		<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" />
    
    Maciej Fijalkowski's avatar
    Maciej Fijalkowski committed
    	<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="http://speed.pypy.org">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></div>
    
    	<hr class="clear" />
    </div>
    <div id="content">
    <div>
    <div id="main">
    <h1 class="title">Python compatibility</h1>
    
    Antonio Cuni's avatar
    Antonio Cuni committed
    <p>PyPy implements the Python language version 2.7.1. 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 1.6
    
    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.</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>
    
    <p>Standard library modules supported by PyPy, in alphabetical order:</p>
    <ul class="simple">
    
    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>
    <p>Python libraries known to work under PyPy (the list is not exhaustive):</p>
    <ul class="simple">
    <li>ctypes</li>
    <li>django (without any DB but sqlite)</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>
    
    <p>won't work.</p>
    </li>
    </ul>
    
    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">
    <ul>
      <li>
      <div class="sidepic">
      <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick" />
    
    <input type="hidden" name="hosted_button_id" value="J268ZTLRE2BW8" />
    
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" />
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
    </form>
        </div>
      </li>
      <li>
        <div class="sidepic">
    
    <script type="text/javascript">
    function validateAmount(amount){
           if(amount.value.match( /^[0-9]+(\.([0-9]+))?$/)){
                   return true;
           }else{
                   alert('You must enter a valid donation.');
                   amount.focus();
                   return false;
           }
    }
    </script>
    <form action="https://checkout.google.com/cws/v2/Donations/622836985124940/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm" onSubmit="return validateAmount(this.item_price_1)" target="_top">
       <input name="item_name_1" type="hidden" value="PyPy Directed Donation via Software Freedom Conservancy, Inc." />
       <input name="item_description_1" type="hidden" value="This is a donation to the Software Freedom Conservancy, Inc. The donation will be directed for the PyPy project." />
       <input name="item_quantity_1" type="hidden" value="1" />
       <input name="item_currency_1" type="hidden" value="USD" />
       <input name="item_is_modifiable_1" type="hidden" value="true" />
       <input name="item_min_price_1" type="hidden" value="5.0" />
       <input name="item_max_price_1" type="hidden" value="25000.0" />
       <input name="_charset_" type="hidden" value="utf-8" />
       <table cellpadding="5" cellspacing="0" width="1%">
           <tr>
               <td align="right" nowrap="nowrap" width="1%">$ <input id="item_price_1" name="item_price_1" onfocus="this.style.color='black'; this.value='';" size="11" style="color:grey;" type="text" value="Enter Amount" />
               </td>
               <td align="left" width="1%">
                   <input alt="Donate" src="https://checkout.google.com/buttons/donateNow.gif?merchant_id=622836985124940&amp;w=115&amp;h=50&amp;style=white&amp;variant=text&amp;loc=en_US" type="image" />
               </td>
           </tr>
       </table>
    </form>
        </div>
      </li>
      <li>
        <div class="sidepic">
    
          <a id="main_download" href="download.html">Download PyPy</a>
    
        </div>
      </li>
    </ul>
    </div>
    </div>
    </div>
    </div></div></div>
    </body>
    
    </html>