# Collected material ###### tags: `planning` ## Python API generators ### [f2py](https://numpy.org/doc/stable/f2py/) Python wrapper generator that is part of NumPy Main limitations: * Doesn't support derived types ### [f90wrap](https://github.com/jameskermode/f90wrap) Fortran to Python interface generator that extends f2yp with derived type support. ### [fmodpy](https://github.com/tchlux/fmodpy) "An easy-to-use Fortran wrapper for Python." Still in development. ### [gfort2py](https://github.com/rjfarmer/gfort2py) Library to allow calling fortran code from python. * Only works with gfortran ### [F2x](https://github.com/DLR-SC/F2x) "A versatile, template-based Fortran wrapper written in Python." * Lacks documentation ### [Forthon](https://github.com/dpgrote/Forthon) "Forthon generates links between Fortran95 and Python." * Lacks documentation ### [SWIG-Fortran](https://github.com/swig-fortran) * Fairly well supported but is still an unfriendly fork with no path to being merged upstream ### Various packages that don't seem to be maintained [fwrap](https://fwrap.readthedocs.io/en/latest/) ## C interfaces from Python ### [ctypes](https://docs.python.org/3/library/ctypes.html) Foreign function library in the Python standard library. ### [cffi](https://cffi.readthedocs.io/en/latest/) Python wrapper generator for C ### [Cython](https://cython.readthedocs.io/en/latest/index.html) Compiler for Python C-extensions. Can load shared libaries. [Making your C library callable from Python by wrapping it with Cython](https://stavshamir.github.io/python/making-your-c-library-callable-from-python-by-wrapping-it-with-cython/) ### [numpy.ctypeslib](https://numpy.org/doc/stable/reference/routines.ctypeslib.html) Module to facilitate working with NumPy arrays in C interfaces `numpy.ctypeslib.as_ctypes` Converting array to C array `numpy.ctypeslib.as_array` Convert C array to NumPy array `numpy.ctypeslib.load_library` Alternative to ctypes.cdll that takes care of platform-specific things ### [numpy.ndarray.ctypes](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.ctypes.html) An object to simplify the interaction of NumPy arrays with the ctypes module `x.ctypes.data` Attribute to access data as C array ### [SWIG](http://www.swig.org/) Python wrapper generator for C ## Tools for patching Python wheels with dynamic libraries * Building Python packages with shared libraries means that the library needs to be present at runtime for the end user. * Tools are available to patch the binary wheels to include these shared libraries. * Support for Windows is currently lacking. ### [delocate](https://github.com/matthew-brett/delocate) Well-established tool for MacOs ### [auditwheel](https://github.com/pypa/auditwheel) Well-established tool for Linux ### [delvewheel](https://github.com/adang1345/delvewheel) Preliminary tool for Windows ## Available guides [Calling Fortran from Python](https://maurow.bitbucket.io/notes/calling_fortran_from_python.html) [Fortran90.org: Interfacing with Python](https://www.fortran90.org/src/best-practices.html#interfacing-with-python) [Fortran Wiki: Generating C Interfaces](http://fortranwiki.org/fortran/show/Generating+C+Interfaces) [Fortran Wiki: Python](http://fortranwiki.org/fortran/show/Python) [Foreign Fortran](https://foreign-fortran.readthedocs.io/en/latest/) [Python-Fortran bindings examples](https://pnavaro.github.io/python-fortran/quickstart.html) [Interfacing Fortran code](https://www.futurelearn.com/info/courses/python-in-hpc/0/steps/65132) [Using fortran from python](https://arogozhnikov.github.io/2015/11/29/using-fortran-from-python.html) [High-Performance Python – Compiled Code and Fortran Interface](https://www.admin-magazine.com/HPC/Articles/High-Performance-Python-2) [Combining Python with Fortran, C and C++](https://metaphor.ethz.ch/fsdb/sam/PythonTutorial/combining.html) [Writing fast Fortran routines for Python](https://sites.engineering.ucsb.edu/~shell/che210d/f2py.pdf) [Interfacing With Other Programming Languages Using Cython](http://www.acme.byu.edu/wp-content/uploads/2014/09/Cython-Wrapping1.pdf) ### Slides [Interfacing Python with Fortran](https://www-uxsup.csx.cam.ac.uk/courses/moved.PythonFortran/f2py.pdf) [Slides from INF3331 lectures – combining Python with Fortran/C/C++](https://www.uio.no/studier/emner/matnat/ifi/INF3331/h11/mixed2.pdf) ## Running Python from Fortran [forcallpy](https://forcallpy.readthedocs.io/en/latest/) [forpy](https://github.com/ylikx/forpy/wiki) [call_py_fort](https://github.com/nbren12/call_py_fort)