A few examples to illustrate the main steps required to build and call Fortran code from Python with the following tools:
Tool |
Pros |
Cons |
ctypes |
Allows for tailor-made wrappers. C-API as byproduct. |
C-bindings and Python-bindings must be written for all data types and procedures (besides the manual effort, some aspects are not intuitive at all). |
f2py |
Little/no manual work. Fortran procedures are automatically given a Pythonic signature. Array dimensions become optional arguments. |
No support for derived data types, abstract interfaces, etc. No possibility for wrapper customization. |
f90wrap |
Support for derived data types, abstract interfaces, etc. Can parse Doxygen (but not FORD) docstrings. |
Procedure signatures remain unchanged (Fortranic, not Pythonic). Procedures with callbacks are excluded (bug?). Support seems limited (just an impression). |
gfort2py |
to do! |
to do! |
A rather comprehensive list of tools to invoke Fortran code from Python can be found here.