Skip to main content

Shed Skin is a restricted-Python-to-C++ compiler.

Project description

Build Status benchmarked by asv

Shed Skin

Shed Skin is a transpiler, that can translate pure, but implicitly statically typed Python 3 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 25 common modules, such as random and re, are currently supported) or any other external library. Also, not all Python features, such as nested functions and variable numbers of arguments, are supported (see the documentation for details).

For a set of over 80 non-trivial programs (at over 25,000 lines in total (sloccount)), measurements show a typical speedup of 1-100 times over CPython 3.14 (average 20 times, median 12 times).

Use Shed Skin when:

  • You have a few hundred lines of code (up to a few thousand), that you want to run at the highest possible speed
  • This code is, or can be made, independent of external libraries
  • You don't want to switch to a faster language (for reasons), or add type annotations (e.g. use Cython)
  • You would prefer to stick with CPython as your (main) interpreter (e.g. no PyPy)
  • You don't mind refactoring your code (potentially a lot!) to make it compatible with Shed Skin

Usage

Compile and run the 'hello, world!' (test.py) example under Linux/OSX:

shedskin build test
build/test

Under Windows:

shedskin build test
build\test.exe

Restrictions

Shed Skin only supports a restricted subset of Python, so one should not expect a given program to compile without any changes, if possible at all. You may have to work a lot, or even start from scratch, to make your code compatible. See the documentation for an overview of the limitations.

Installation

Shed Skin depends on some other projects, such as the Boehm garbage collector. Please see the documentation on how to install these.

Comparison

Some timings for the Shed Skin 'sieve' example (n=100000000) and several Python implementations/optimizers:

cpython 3.10.6:     13.4 seconds
cpython 3.11.0:     11.4
nuitka 0.6.16:      11.4
pypy 3.9.12:        5.8
numba 0.56.4:       2.5
shedskin 0.9.9:     1.9
shedskin 0.9.9:     1.8  (using --nowrap --nobounds)

Note that Numba defaults to int64 as integer type, while Shed Skin defaults to int32. Performance is practically equal when using shedskin --int64.

The following shows a comparison of speedups versus CPython 3.10 for Shed Skin and Pypy, for most of the Shed Skin examples.

These measurements were performed for the git tag 'performance_comparison'. As can be seen, we allowed PyPy to stabilize before measuring.

Screenshots

Some screenshots of the example programs in action:

(pylot)

(c64)

(pycsg)

(othello2)

(doom)

This video shows the dramatic difference in performance for the DOOM example before and after compilation

Contributors

The following people have contributed to Shed Skin development:

  • Shakeeb Alireza
  • Hakan Ardo
  • Brian Blais
  • Paul Boddie
  • Francois Boutines
  • Wyatt S. Carpenter
  • Djamel Cherif
  • James Coughlan
  • Mark Dewing
  • Mark Dufour
  • Artem Egorkine
  • Michael Elkins
  • Moataz Elmasry
  • Enzo Erbano
  • Ernesto Ferro
  • Salvatore Ferro
  • FFAO
  • Victor Garcia
  • Davide Gessa
  • Luis M. Gonzales
  • Fahrzin Hemmati
  • Folkert van Heusden
  • Karel Heyse
  • Humhue
  • Johan Kristensen
  • Kousuke
  • Denis de Leeuw Duarte
  • Van Lindberg
  • David Marek
  • Douglas McNeil
  • Andy Miller
  • Jeff Miller
  • Danny Milosavljevic
  • Joaquin Abian Monux
  • John Nagle
  • Harri Pasanen
  • Brent Pedersen
  • Joris van Rantwijk
  • Retsyo
  • Pierre-Marie de Rodat
  • Jeremie Roquet
  • Mike Schrick
  • SirNotAppearingInThisTutorial
  • Paul Sokolevsky
  • Thomas Spura
  • Joerg Stippa
  • Dan Stromberg
  • Dave Tweed
  • Jaroslaw Tworek
  • Tony Veijalainen
  • Yuri Victorovich
  • Pavel Vinogradov
  • Jason Ye
  • Liu Zhenhai
  • Joris van Zwieten

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shed_skin-0.9.12.tar.gz (5.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shed_skin-0.9.12-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file shed_skin-0.9.12.tar.gz.

File metadata

  • Download URL: shed_skin-0.9.12.tar.gz
  • Upload date:
  • Size: 5.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for shed_skin-0.9.12.tar.gz
Algorithm Hash digest
SHA256 a067ffda5b52cf85b4c45bf9654cdbd949a0530007e5b93cf1dbb9fcbca1e45e
MD5 df1c50c88137af1b1a71d25cff4c5fbb
BLAKE2b-256 3b8eca870b2a6f712e950042e15c958d3927cad625c3874e125a5d064bdb91ca

See more details on using hashes here.

File details

Details for the file shed_skin-0.9.12-py3-none-any.whl.

File metadata

  • Download URL: shed_skin-0.9.12-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for shed_skin-0.9.12-py3-none-any.whl
Algorithm Hash digest
SHA256 7008eb464749b58b0c3e1ef8032507c86e4333510d8310e78487acd2d2a60fca
MD5 35120e4fda0bcab71de876c471e6da12
BLAKE2b-256 669a12cf1bda9c31def4e5feedab4b6047163c8b6d8d9d8e2c2a2c711063651a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page