# Looking for some f2py examples

**URL:** <https://fortran-lang.discourse.group/t/looking-for-some-f2py-examples/7424>\
**Category:** Uncategorized\
**Created:** [February 17, 2024, 5:38pm UTC](https://fortran-lang.discourse.group/t/looking-for-some-f2py-examples/7424 "2024-02-17T17:38:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [February 17, 2024, 5:38pm UTC](https://fortran-lang.discourse.group/t/looking-for-some-f2py-examples/7424/1 "2024-02-17T17:38:16Z")

</div>

What are some good examples to study of libraries out there that use F2py to wrap Fortran code and publish a Python package? Looking for:

- non-trivial Fortran library (i.e., not just a single 50 year old FORTRAN 77 file)
- automated publishing to PyPi and conda-forge for all platforms (e.g., from GitHub CI)

---

<div class="post-metadata">

**Author:** ![fedebenelli](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fedebenelli/32/1823_2.png) [@fedebenelli](https://fortran-lang.discourse.group/u/fedebenelli)\
**Post date:** [February 17, 2024, 7:24pm UTC](https://fortran-lang.discourse.group/t/looking-for-some-f2py-examples/7424/2 "2024-02-17T19:24:35Z")

</div>

A library that I did when starting my PhD and needs a rework since I don’t like using CMake doesn’t have very complex Fortran code but it does CI and automated publishing:

> **[GitHub - fedebenelli/PyForFluids: PyForFluids: Fluids Properties Based on...](https://github.com/fedebenelli/PyForFluids/)**
>
> PyForFluids: Fluids Properties Based on Equations of State - fedebenelli/PyForFluids

Now I’m focusing on a more complex and OOP in the Fortran-side library and just recently started drafting a Python interface that could be used with f2py. Still not full CI/CD since it’s not the focus. To hide the Fortran objects I use a singleton object that gets redefined when needed, I took that idea from a post where @ivanpribec commented about that pattern which I didn’t knew before, and fits pretty well for my use case.

> <https://github.com/ipqa-research/yaeos/tree/5-python-api/python>
>
> //github.com/ipqa-research/yaeos/tree/5-python-api/python

---

<div class="post-metadata">

**Author:** ![zaikunzhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zaikunzhang/32/785_2.png) [@zaikunzhang](https://fortran-lang.discourse.group/u/zaikunzhang)\
**Post date:** [February 18, 2024, 4:28am UTC](https://fortran-lang.discourse.group/t/looking-for-some-f2py-examples/7424/3 "2024-02-18T04:28:46Z")

</div>

[PDFO](https://www.pdfo.net) is such a project. It wraps Powell’s F77 derivative-free optimization (DFO) solvers using f2py and publishes the package on PyPI using GitHub Actions.

PDFO will be replaced with [PRIMA](http://www.libprima.net), which provides the reference implementation of Powell’s DFO solvers in modern Fortran (F2008 or above). It will be wrapped in Python [using pybind11](https://github.com/libprima/prima/pull/124).

---

<div class="post-metadata">

**Author:** ![rgoswami](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/rgoswami/32/23_2.png) [@rgoswami](https://fortran-lang.discourse.group/u/rgoswami)\
**Post date:** [February 18, 2024, 4:50am UTC](https://fortran-lang.discourse.group/t/looking-for-some-f2py-examples/7424/4 "2024-02-18T04:50:18Z")

</div>

[Gaussjacobiquad](https://github.com/HaoZeke/Gaussjacobiquad) demonstrates modern usage with ISOC compatible code and some internal derived types.

It doesn’t push to pypi yet but that’s easily arranged.
