# Fortran OOP from Python

**URL:** <https://fortran-lang.discourse.group/t/fortran-oop-from-python/3577>\
**Category:** Help\
**Created:** [May 28, 2022, 11:34am UTC](https://fortran-lang.discourse.group/t/fortran-oop-from-python/3577 "2022-05-28T11:34:29Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [May 28, 2022, 12:21pm UTC](https://fortran-lang.discourse.group/t/fortran-oop-from-python/3577/3 "2022-05-28T12:21:45Z")

</div>

It depends on detailed the Python side needs insight into the Fortran library. The easy case is when you only want to use your Fortran objects in Python, as you only have to export all hooks via `bind(c)`. This step I’m at the moment doing mostly manually, because while well-defined, many objects have slightly different demands on the wrapper.

If you have a well-defined abstract base class you can implement this via a callback on the Fortran side, which takes C function and data pointer as implementation. I use this technique to implement logging for example. Viewing into Fortran data, dispatching an object based on its class or using memory allocators provided by a foreign runtime is more difficult. The former two are possible to implement, but can become a bit tedious, the latter I think is quite challenging with the current CFI features.

I gave a presentation on this topic a while ago, see

> [@Using objects across language boundaries](https://fortran-lang.discourse.group/t/using-objects-across-language-boundaries/2776):
>
> I’m giving a seminar next week on object-oriented programming in Fortran with focus on using Fortran objects in other languages, like C or Python. While the actual seminar is currently a closed round, we are sharing the presentations afterwards (or in advance). You can find my take on object-oriented programming in more than one language at [Using objects across language boundaries — Fortran OOP Seminar Series](https://awvwgk.github.io/foopss/). The source is available here: I’ll probably tinker on the presentation til Thursda…

---

_[View the full topic](https://fortran-lang.discourse.group/t/fortran-oop-from-python/3577)._
