Python-to-Fortran/C transpiler for scientific high-performance computing that automatically converts Python code into optimized low-level code.
npx @tessl/cli install tessl/pypi-pyccel@2.0.0A Python-to-Fortran/C transpiler for scientific high-performance computing that automatically converts Python code into optimized low-level code while maintaining Python syntax. Pyccel enables significant performance improvements for mathematical and scientific computations by transpiling Python functions and classes to compiled languages, with seamless integration into existing Python workflows.
pip install pyccelimport pyccel
from pyccel import epyccel, lambdifyFor decorators:
from pyccel.decorators import pure, elemental, inline, stack_arrayfrom pyccel import epyccel
import numpy as np
# Define a function to accelerate
def compute_sum(x, y):
"""Simple computation function."""
return x + y
# Accelerate the function using Fortran backend
compute_sum_fast = epyccel(compute_sum, language='fortran')
# Use the accelerated function
result = compute_sum_fast(5.0, 3.0)
print(result) # 8.0
# For NumPy array operations
def array_multiply(arr1, arr2):
"""Multiply two NumPy arrays element-wise."""
return arr1 * arr2
# Accelerate array operations
array_multiply_fast = epyccel(array_multiply, language='fortran')
# Use with NumPy arrays
a = np.array([1.0, 2.0, 3.0])
b = np.array([4.0, 5.0, 6.0])
result = array_multiply_fast(a, b)
print(result) # [4. 10. 18.]Pyccel follows a multi-stage compilation pipeline:
The transpiler supports both embedded mode (epyccel function) for interactive use and command-line mode for batch processing, enabling flexible integration into existing Python scientific computing workflows.
Core functions for accelerating Python code from within Python scripts, enabling interactive transpilation and immediate performance improvements without external tooling.
def epyccel(function_class_or_module, *, language='fortran', **kwargs): ...
def lambdify(expr, args, *, result_type=None, **kwargs): ...Console commands for transpiling Python files and managing Pyccel projects from the command line, supporting batch processing and integration with build systems.
pyccel filename.py [options]
pyccel-clean [options]
pyccel-test [options]Decorators that provide fine-grained control over transpilation behavior, optimization hints, and code generation options for enhanced performance.
@pure
@elemental
@inline
@stack_array('array1', 'array2')
@allow_negative_index('arr')Comprehensive type system supporting Python's native types, NumPy arrays, and custom data structures with automatic type inference and manual type annotations.
# Type annotation support
def func(x: 'float', y: 'int[:]') -> 'float': ...
# NumPy type integration
from pyccel.ast.numpytypes import NumpyFloat64Type, NumpyNDArrayTypefrom pyccel.errors.errors import PyccelError
class PyccelError(Exception):
"""Base exception for Pyccel transpilation errors."""from types import FunctionType, ModuleType
from typing import Union, Dict, List, Tuple, Optional, Any, Callable
# Common type aliases used throughout Pyccel
FunctionOrClass = Union[FunctionType, type]
ModuleOrString = Union[ModuleType, str]
AcceleratedObject = Union[FunctionType, type, ModuleType]
CompilerOptions = Optional[Union[str, List[str]]]import pyccel
print(pyccel.__version__) # "2.0.1"
# Version components
from pyccel.version import __version__