Interfacing Fortran with python in 2025

You could stick with pybind11 and just use gfortran to write the C headers for your bind(c) procedures (the ones implemented in Fortran):

To generate the header use:

$ gfortran -fc-prototypes -fsyntax-only fortranlib.f90 > fortranlib.h

Then you can just follow your standard C/C++ + pybind11 workflow.


I haven’t used pybind11 (or nanobind) before. Does a C function prototype contain all the needed information to write the pybind11 binding? If yes, there may be some ways to automate this. I’ve given a talk about something similar recently: FOSDEM 2025 - Easier API Interoperability: writing a bindings Generator to C/C++ with Coccinelle