Essentially I want to do something similar as described here: redirecting the python output in an application embedding python. The best answer seems to be this one, because it is written only in C / C++ (mixing Python and C / C++ seems not clean to me).
Still I'm not happy with the answers. First of all when looking at https://docs.python.org/3/c-api/file.html, it seems that I should not use PyFile_FromFile(..) anymore, and I'm not sure whether PyFile_FromFd(..) is the Python 3 substitute, looking at the warning in red. Second I only want to redirect the output generated by my calls to Python functions, e.g. PyRun_SimpleString(..), not the whole program output. Essentially my application is compiled as a shared library and when loaded should only redirect it's own output.
An application of library would be a custom Python GUI: A GUI which loads the library, the user can enter a string which will be sent to the library, which gives it to PyRun_SimpleString(..) and returns the output. The GUI will then will then display the output.