or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

command-line.mddecorators.mdembedded-acceleration.mdindex.mdtype-system.md
tile.json

tessl/pypi-pyccel

Python-to-Fortran/C transpiler for scientific high-performance computing that automatically converts Python code into optimized low-level code.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyccel@2.0.x

To install, run

npx @tessl/cli install tessl/pypi-pyccel@2.0.0

index.mddocs/

Pyccel

A 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.

Package Information

  • Package Name: pyccel
  • Language: Python
  • Installation: pip install pyccel
  • Version: 2.0.1
  • License: MIT

Core Imports

import pyccel
from pyccel import epyccel, lambdify

For decorators:

from pyccel.decorators import pure, elemental, inline, stack_array

Basic Usage

from 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.]

Architecture

Pyccel follows a multi-stage compilation pipeline:

  • Parser: Converts Python source code to Abstract Syntax Tree (AST)
  • Semantic Analysis: Type inference and validation
  • Code Generation: Translates Python AST to target language (Fortran/C)
  • Compilation: Compiles generated code and creates Python extensions
  • Runtime Integration: Seamless integration with Python via compiled extensions

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.

Capabilities

Embedded Acceleration Functions

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): ...

Embedded Acceleration

Command-Line Interface

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]

Command-Line Tools

Function Decorators

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')

Decorators

Type System Integration

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, NumpyNDArrayType

Type System

Types

Exception Types

from pyccel.errors.errors import PyccelError

class PyccelError(Exception):
    """Base exception for Pyccel transpilation errors."""

Import Types

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]]]

Version Information

import pyccel
print(pyccel.__version__)  # "2.0.1"

# Version components
from pyccel.version import __version__