PRIK¶
Python Runtime Interop Kit.
Turn Fortran into natural Python APIs.
Build clean, importable native extensions from supported Fortran without
writing low-level binding code. PRIK preserves modules, derived types, arrays,
and native behavior, and generates an editable .pyi contract so you can
shape the Python API.
Project status: Alpha (0.1.x). Core Fortran wrapper workflows are
implemented and tested across supported compilers, but public APIs may still
change before 1.0.
The complete example below builds with one command:
python3 -m prik points.f90 --out geometry
See it in action¶
Create points.f90:
module points
implicit none
type :: point
real(8) :: x = 0.0d0
real(8) :: y = 0.0d0
end type point
contains
subroutine move(item, dx, dy)
type(point), intent(inout) :: item
real(8), intent(in) :: dx, dy
item%x = item%x + dx
item%y = item%y + dy
end subroutine move
real(8) function norm_squared(item) result(value)
type(point), intent(in) :: item
value = item%x * item%x + item%y * item%y
end function norm_squared
end module points
Generated Python API:
import numpy as np
import geometry.points as points
item = points.point(x=np.float64(3.0), y=np.float64(4.0))
points.move(item, np.float64(1.0), np.float64(-2.0))
print(item.x, item.y) # 4.0 2.0
print(points.norm_squared(item)) # 20.0
No manual bindings are required. From this source, PRIK creates a Python namespace, a class with accessible fields, a mutating procedure, and a function.
Want a different Python API? Edit the generated .pyi contract to rename or
hide exports, flatten namespaces, define constructors and methods, or create
overloads. The contract guide shows
the available edits.
How it works¶
- Write standard Fortran.
- Run
prikon the source. - Import the generated native extension.
- Optionally edit the generated
.pyicontract to shape the Python API.
No manual binding code or low-level boilerplate.
Key Features¶
- Fortran modules exposed as Python namespaces and derived types as classes
- NumPy arrays with explicit dtype, shape, and layout checks
- Allocatable and pointer arrays with explicit lifetime operations
- Immediate Python callbacks and overloaded interfaces
- Editable
.pyicontracts and readable generated docstrings - Early, clear errors when a boundary cannot be wrapped
- Low wrapper overhead measured against NumPy's f2py in a reproducible benchmark suite
Measured Performance¶
Low wrapper overhead, measured against NumPy's f2py.
The latest published benchmark runs both tools against the same Fortran kernels through their normal generated interfaces. Results are machine-dependent; the detailed page records the complete environment and reproduction method.
Runtime-call performance — values above 1.0× mean PRIK is faster.
Clean end-to-end build time — lower times are better.
View the full results and methodology →
Ready to wrap your Fortran code?