|Original author(s)||Mark Dufour, others|
0.9.4 / June 16, 2013
|Written in||Python, C++|
|Operating system||Cross-platform: Linux, Mac OS X, Windows|
|License||GPL 3, BSD, MIT|
Shed Skin is a Python to C++ programming language compiler. It is experimental, and can translate pure, but implicitly statically typed Python programs into optimized C++. It can generate stand-alone programs or extension modules that can be imported and used in larger Python programs.
Besides the typing restriction, programs cannot freely use the Python standard library, although about 20 common modules, such as random, itertools and re (regular expressions), are supported as of 2011. Also, not all Python features, such as nested functions and variable numbers of arguments, are supported. Many introspective dynamic parts of the language are unsupported. For example, functions like getattr, and hasattr are unsupported.
As of June 2016 for a set of 75 non-trivial test programs (at over 25,000 lines in total (sloccount)), measurements show a typical speedup of 2-20 times over Psyco, and 2-200 times over CPython. Shed Skin is still in an early stage of development, so many other programs will not compile unmodified.
Shed Skin can be used to generate standalone executables which need only the C++ runtime libraries. It can also be used to generate CPython modules. This allows compiling parts of larger programs with Shed Skin, while running the other parts using regular CPython.
Another use has been to wrap C++ classes using Shed Skin to allow C++ classes to be used as Python classes.
The license of the Shed Skin source code is under two parts. The main compiler code is under the GNU General Public License (GPL). The supporting code that it uses as a run time library is under a BSD or MIT license depending on the module. This allows compiling programs which are considered under the GPL or are not considered under the GPL.
Shed Skin combines Ole Agesen's Cartesian Product Algorithm (CPA) with the data-polymorphic part of John Plevyak's Iterative Flow Analysis (IFA). Version 0.6 introduced scalability improvements which repeatedly analyze larger versions of a program (in addition to the mentioned techniques), until it is fully analyzed. This allows Shed Skin to do type inference on larger programs than previously. It starts with an empty callgraph, essentially, and slowly adds to it, until the whole call graph has been added. A graph has been published by the author, showing analysis times for 50 example programs, at a total of around 15,000 lines.
For version 0.9 the following 25 modules are largely supported. Several of these, such as os.path, were compiled to C++ using Shed Skin.
- collections (defaultdict, deque)
- ConfigParser (no SafeConfigParser)
- csv (no Dialect, Sniffer)
- itertools (no starmap)
- struct (no Struct, pack_into, unpack_from)
- first Shed Skin release
- Learning Python Book section on Shed Skin
- Shed Skin tutorial ("Python Subset Restrictions" section)
- Speed up your Python: Unladen vs. Shed Skin vs. PyPy vs. Cython vs. C
- Taking on Shed-Skin
- Speeding up Python code with Shed Skin
- MiniLight, minimal global illumination renderer benchmark
- Shed Skin webpage
- Wrapping C++ classes using Shed Skin
- Master Thesis Mark Dufour, "Shed Skin. An Optimizing Python-to-C++ Compiler", April 19, 2006
- Type inference scalability, 2010-12
- Shedskin 0.9 release notes