Python-to-Fortran/C transpiler for scientific high-performance computing that automatically converts Python code into optimized low-level code.
—
Console commands for transpiling Python files and managing Pyccel projects from the command line, supporting batch processing and integration with build systems.
The primary command-line interface for transpiling Python files to optimized compiled code.
pyccel filename.py [options]filename.py # Path to Python file to transpile-h, --help # Show help message and exit
-V, --version # Show version and exit
-v, --verbose # Increase verbosity (use -v, -vv, -vvv)
--time-execution # Print time spent in each execution section
--developer-mode # Enable developer error mode-x, --syntax-only # Stop after syntactic parsing
-e, --semantic-only # Stop after semantic analysis
-t, --convert-only # Stop after translation, before build--language {fortran,c,python} # Target language (default: fortran)--compiler-family {GNU,intel,PGI,nvidia,LLVM} # Compiler family (default: GNU)
--compiler-config CONFIG.json # Load compiler config from JSON file--flags FLAGS # Additional compiler flags
--wrapper-flags FLAGS # Additional wrapper compiler flags
--debug / --no-debug # Compile with debug flags
--include DIR [DIR ...] # Additional include directories
--libdir DIR [DIR ...] # Additional library directories
--libs LIB [LIB ...] # Additional libraries to link
--output DIR # Output folder (default: input file's folder)--mpi # Enable MPI support
--openmp # Enable OpenMP support--conda-warnings {off,basic,verbose} # Conda warning level (default: basic)Usage examples:
# Basic transpilation to Fortran
pyccel my_script.py
# Transpile to C with debug mode
pyccel my_script.py --language c --debug
# Transpile with OpenMP support
pyccel compute.py --openmp --verbose
# Transpile with custom compiler and flags
pyccel simulation.py --compiler-family intel --flags "-O3 -march=native"
# Stop after semantic analysis for debugging
pyccel test.py --semantic-only --developer-mode
# Transpile with MPI and custom output directory
pyccel parallel_code.py --mpi --output ./build --verboseRemoves generated Pyccel files and build artifacts from the current directory or specified paths.
pyccel-clean [options]Usage examples:
# Clean current directory
pyccel-clean
# Clean with verbose output
pyccel-clean --verboseRuns Pyccel's test suite or tests specific Python files for transpilation compatibility.
pyccel-test [options] [files...]--language {fortran,c,python} # Test with specific target language
--mpi # Test with MPI support
--openmp # Test with OpenMP support
--verbose # Verbose test outputUsage examples:
# Run all tests
pyccel-test
# Test specific files
pyccel-test my_module.py another_file.py
# Test with Fortran backend and MPI
pyccel-test --language fortran --mpi test_parallel.py
# Run tests with verbose output
pyccel-test --verbosefrom pyccel.commands.console import pyccel
def pyccel():
"""
Main Pyccel console command function.
Parses command-line arguments and executes the transpilation pipeline
with the specified options. Handles all stages from syntax parsing
through compilation and executable generation.
"""from pyccel.commands.pyccel_clean import pyccel_clean_command
def pyccel_clean_command():
"""
Clean generated Pyccel files command function.
Removes __epyccel__ directories, compiled extensions, and other
build artifacts created during transpilation process.
"""from pyccel.commands.pyccel_test import pyccel_test_command
def pyccel_test_command():
"""
Pyccel test execution command function.
Runs transpilation tests on specified files or the full test suite,
validating correct behavior across different backends and options.
"""import argparse
from pyccel.commands.console import MyParser
class MyParser(argparse.ArgumentParser):
"""
Custom argument parser that displays help on error.
Extends ArgumentParser to automatically show help message
when invalid arguments are provided.
"""
def error(self, message):
"""Display error message and help, then exit."""PYCCEL_DEBUG_MODE # Default debug mode (True/False)
PYCCEL_ERROR_MODE # Error reporting mode (user/developer)
PYTEST_XDIST_WORKER # Parallel test worker ID (used internally){
"family": "GNU",
"fortran": {
"compiler": "gfortran",
"flags": ["-O3", "-fPIC"],
"libs": ["gfortran"]
},
"c": {
"compiler": "gcc",
"flags": ["-O3", "-fPIC"],
"libs": ["m"]
}
}original_file.py # Original Python file
__epyccel__/ # Build directory
├── mod_<random>.py # Generated Python module
├── mod_<random>.f90 # Generated Fortran code
├── mod_<random>.so # Compiled shared library
└── mod_<random>.lock # File lock for parallel buildsWhen the input file contains if __name__ == '__main__':, Pyccel generates:
filename # Executable binary (Unix)
filename.exe # Executable binary (Windows)Install with Tessl CLI
npx tessl i tessl/pypi-pyccel