f2py
Fortran to Python interface generator
TLDR
Generate Python wrapper for Fortran
SYNOPSIS
f2py [options] fortran-files [options]
DESCRIPTION
f2py (Fortran to Python) is a NumPy tool that creates Python bindings for Fortran code. It generates wrapper modules that allow calling Fortran subroutines and functions directly from Python.
The tool automatically handles type conversion between Python/NumPy arrays and Fortran arrays. It parses Fortran source code or signature files to determine interfaces, then generates C wrapper code compiled into a Python extension module.
f2py enables using high-performance Fortran libraries in Python scientific computing workflows without rewriting existing code.
PARAMETERS
FORTRAN-FILES
Fortran source files (.f, .f90, .f95).-c
Compile and build extension module.-m NAME
Set module name.-h FILE
Generate signature file.--fcompiler NAME
Specify Fortran compiler.-l LIBRARY
Link with library.-L PATH
Library search path.-I PATH
Include search path.--help-fcompiler
List available Fortran compilers.--help
Display help information.
CAVEATS
Requires Fortran compiler and NumPy installation. Complex Fortran constructs may need signature file tweaks. Array ordering differs between Fortran (column-major) and C (row-major).
HISTORY
f2py was created by Pearu Peterson in the late 1990s and became part of NumPy. It bridges Python's scientific computing ecosystem with decades of Fortran numerical libraries, enabling their continued use in modern Python workflows.
