Pythran

0.18.1 · active · verified Sat Apr 11

Pythran is an Ahead-of-Time (AOT) compiler that translates a subset of Python, primarily focused on scientific computing and numerical kernels, into native C++14 modules. It aims to provide C++/Fortran-like performance for Python code, leveraging multi-cores and SIMD instructions. The current stable version is 0.18.1, and it actively maintains a release cadence of several updates per year, supporting Python 3.7 and upward.

Warnings

Install

Imports

Quickstart

Create a Python file with numerical kernels annotated for export. Compile it using the `pythran` command-line tool, then import the resulting native module. This example defines a dot product function.

# dprod.py
""" Naive dotproduct! Pythran supports numpy.dot """
#pythran export dprod(int list, int list)
def dprod(l0, l1):
    """WoW, generator expression, zip and sum."""
    return sum(x * y for x, y in zip(l0, l1))

# To compile the Python file to a native module:
# pythran dprod.py

# Then, import and use the compiled module:
# python -c 'import dprod; print(dprod.dprod([1,2,3], [4,5,6]))'

view raw JSON →