# PRIK — Bring native Fortran and C code to Python

**URL:** <https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069>\
**Category:** Announcements\
**Created:** [August 27, 2026, 1:58am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069 "2026-08-27T01:58:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Said-H](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Said-H](https://fortran-lang.discourse.group/u/Said-H)\
**Post date:** [August 27, 2026, 1:58am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/1 "2026-08-27T01:58:42Z")

</div>

Hi everyone,

I’d like to introduce **[PRIK](https://github.com/PyNumLab/prik) (Python Runtime Interop Kit)**, an open-source project I’ve been working on for generating native Python bindings for Fortran and C code.

The basic usage can be as simple as:

```auto
pip install prik
python3 -m prik my_module.f90 --out my_module

```

which produces an importable Python extension from the Fortran source.

One of the main ideas behind PRIK is that the generated Python API does not have to exactly mirror the native API.

PRIK can generate an editable `.pyi` **contract** describing the Python/native boundary:

```auto
python3 -m prik generate --pyi my_module.f90 --out contracts

```

The contract can then be edited to reshape the Python-facing API—for example, to:

- rename procedures
- turn procedures into methods
- hide native arguments
- expose native outputs as Python return values
- expose overloads and callbacks.

The original Fortran source does not need to be modified.

Supported features include modules, derived types (as Python classes), multidimensional arrays with NumPy interop, strings, allocatables, pointers, optional arguments, generics, callbacks, and several other common modern Fortran constructs.

Compared with the f2py route, PRIK focuses on letting you design a more Pythonic API (renames, methods, return-value projection, hidden arguments, etc.) while still generating a native extension.

I have also been testing PRIK against real libraries rather than only small wrapper tests. The current validation suite includes:

- **BLAS** — 155 routines
- **LAPACK** — 127 double-precision routines
- **FFTPACK** — 31 procedures
- **MINPACK** — 22 procedures, including callbacks
- **BSPLINE-FORTRAN** — including modern Fortran classes

There is also C support, currently with a smaller supported surface, with real-library tests against libm and TA-Lib.

PRIK is still **alpha** , so the API may change before 1.0. Fortran support is currently considerably more mature than C support.

Documentation:

> **[PRIK — Bring Native Code to Python](https://pynumlab.github.io/prik/)**
>
> PRIK generates native Python bindings for Fortran and C code.

GitHub:

> **[GitHub - PyNumLab/prik: Bring Native Code to Python with editable .pyi...](https://github.com/PyNumLab/prik)**
>
> Bring Native Code to Python with editable .pyi contracts

---

<div class="post-metadata">

**Author:** ![weixing1531](https://avatars.discourse-cdn.com/v4/letter/w/a88e57/32.png) [@weixing1531](https://fortran-lang.discourse.group/u/weixing1531)\
**Post date:** [August 27, 2026, 3:33am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/2 "2026-08-27T03:33:00Z")

</div>

Support Fortran OOP？ **Type-Bound Methods？**

Like gfort2py

---

<div class="post-metadata">

**Author:** ![Said-H](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Said-H](https://fortran-lang.discourse.group/u/Said-H)\
**Post date:** [August 27, 2026, 3:40am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/3 "2026-08-27T03:40:18Z")

</div>

> Support Fortran OOP？

Yes, try it

---

<div class="post-metadata">

**Author:** ![weixing1531](https://avatars.discourse-cdn.com/v4/letter/w/a88e57/32.png) [@weixing1531](https://fortran-lang.discourse.group/u/weixing1531)\
**Post date:** [August 27, 2026, 4:44am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/4 "2026-08-27T04:44:40Z")

</div>

Windows Not yet supported!

msys2 supported?

---

<div class="post-metadata">

**Author:** ![Said-H](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Said-H](https://fortran-lang.discourse.group/u/Said-H)\
**Post date:** [August 27, 2026, 4:49am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/5 "2026-08-27T04:49:01Z")

</div>

> Windows Not yet supported!
> 
> msys2 supported?

No, not yet.

---

<div class="post-metadata">

**Author:** ![MuellerSeb](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/muellerseb/32/7568_2.png) [@MuellerSeb](https://fortran-lang.discourse.group/u/MuellerSeb)\
**Post date:** [September 1, 2026, 7:51pm UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/6 "2026-09-01T19:51:50Z")

</div>

This sounds amazing! Will keep an eye on this project!

---

<div class="post-metadata">

**Author:** ![MuellerSeb](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/muellerseb/32/7568_2.png) [@MuellerSeb](https://fortran-lang.discourse.group/u/MuellerSeb)\
**Post date:** [September 1, 2026, 10:05pm UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/7 "2026-09-01T22:05:03Z")

</div>

How could this be integrated with [scikit-build-core](https://github.com/scikit-build/scikit-build-core)?

---

<div class="post-metadata">

**Author:** ![Said-H](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Said-H](https://fortran-lang.discourse.group/u/Said-H)\
**Post date:** [September 2, 2026, 1:01am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/8 "2026-09-02T01:01:15Z")

</div>

I have never used scikit-build-core, but from my look into it, you can add something to CMakeLists.txt like:

```makefile
add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo.so
    COMMAND prik
            ${CMAKE_CURRENT_SOURCE_DIR}/foo.f90
            --out ${CMAKE_CURRENT_BINARY_DIR}/foo.so
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/foo.f90
)

add_custom_target(foo ALL
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/foo.so
)

```

or do you have something else in mind?

---

<div class="post-metadata">

**Author:** ![MuellerSeb](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/muellerseb/32/7568_2.png) [@MuellerSeb](https://fortran-lang.discourse.group/u/MuellerSeb)\
**Post date:** [September 2, 2026, 6:51am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/9 "2026-09-02T06:51:48Z")

</div>

This seems like the build process is then controlled by prik, but I would prefer to control the compilation with the used cmake script.

Maybe take a look at the f2py extension of scikit-build: [GitHub - scikit-build/f2py-cmake: F2Py helpers for CMake · GitHub](https://github.com/scikit-build/f2py-cmake)

I think prik could be a promising step forward for packaging compiled fortran extensions with derived type support into wheels using scikit-build.

---

<div class="post-metadata">

**Author:** ![Said-H](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Said-H](https://fortran-lang.discourse.group/u/Said-H)\
**Post date:** [September 13, 2026, 2:59pm UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/10 "2026-09-13T14:59:55Z")

</div>

> [@MuellerSeb](#):
>
> This seems like the build process is then controlled by prik, but I would prefer to control the compilation with the used cmake script.
> 
> Maybe take a look at the f2py extension of scikit-build: [GitHub - scikit-build/f2py-cmake: F2Py helpers for CMake · GitHub](https://github.com/scikit-build/f2py-cmake)
> 
> I think prik could be a promising step forward for packaging compiled fortran extensions with derived type support into wheels using scikit-build.

Thanks for the suggestion. PRIK now has first-class cmake/scikit-build-core integration.

[CMake integration guide](https://pynumlab.github.io/prik/user/guide/cmake/)  
[Runnable CMake example](https://github.com/PyNumLab/prik/tree/main/examples/cmake?utm_source=chatgpt.com)

---

<div class="post-metadata">

**Author:** ![MuellerSeb](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/muellerseb/32/7568_2.png) [@MuellerSeb](https://fortran-lang.discourse.group/u/MuellerSeb)\
**Post date:** [September 14, 2026, 8:11am UTC](https://fortran-lang.discourse.group/t/prik-bring-native-fortran-and-c-code-to-python/11069/11 "2026-09-14T08:11:52Z")

</div>

Wow. That was fast! I will definitely have a look at this.
