How to call Python functions from C++, good description

Eigil Krogh Sorensen 121 Reputation points
2025-08-14T21:08:34.4+00:00

Where do I find a good description of how to call Python functions from a C++ program ?

Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. Varsha Dundigalla(INFOSYS LIMITED) 1,110 Reputation points Microsoft External Staff
    2025-08-15T08:05:01.8033333+00:00

    Thank you for sharing details.

    Authoritative and Practical Guides

    1. Official Python Docs – Embedding Python
    1. Python/C API Reference Manual
    1. Coveros Guide – Calling Python Code from C++
    1. pybind11 Documentation
    • A modern C++11 header-only library that simplifies calling Python from C++ and vice versa.
    • Ideal for clean, readable code and minimal boilerplate.
    • https://pybind11.readthedocs.io/ [2]
    1. Stack Overflow – Calling Python from C/C++

    Internal Microsoft Learn Resources

    • Write C++ extensions for Python - Visual Studio (Windows)
      This guide explains how to use the CPython API to expose C++ functions to Python, including how to use PyObject*, PyMethodDef, and PyModuleDef to register and call functions .
    • The Working Programmer - Python: Functions | Microsoft Learn
      Offers foundational understanding of Python functions, including eval, exec, and dir, which are useful when dynamically interacting with Python from C++.
      References

    [1] Calling a python method from C/C++, and extracting its return value

    [2] Calling Python From C++: A Quick Guide to Integration

    [3] Write C++ extensions for Python - Visual Studio (Windows) | Microsoft Learn

    [4] The Working Programmer - Python: Functions | Microsoft Learn

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Darran Rowe 2,346 Reputation points
    2025-08-14T21:47:53.8466667+00:00

    The python documentation is the best source that I know of here. I don't know if there is a C++ library to encapsulate this, so it uses the C interface.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.