extending and embedding python the following example illustrates the use of these macrospyobject *py_wrapper(pyobject *selfpyobject *argspyarg_parsetuple(argspy_begin_allow_threads result run_long_calculation(args)py_end_allow_threads return py_buildvalue(fmt,result)embedding the python interpreter the python interpreter can also be embedded into applications with embeddingthe python interpreter operates as programming library where programs can initialize the interpreterhave the interpreter run scripts and code fragmentsload library modulesand manipulate functions and objects implemented in python an embedding template with embeddingyour program is in charge of the interpreter here is simple program that illustrates the most minimal embedding possible#include int main(int argcchar **argvpy_initialize()pyrun_simplestring("print('hello world')")py_finalize()return in this examplethe interpreter is initializeda short script is executed as stringand the interpreter is shut down before proceeding any furtherit is usually good idea to get the prior example working first compilation and linking to compile an embedded interpreter on unixyour code must include the "python hheader file and link against the interpreter library such as libpython the header file is typically found in /usr/local/include/python and the library is typically found in /usr/local/lib/python /config for windowsyou will need to locate these files in the python installation directory be aware that the interpreter may depend on other libraries you need to include when linking unfortunatelythis tends to be platform-specific and related to how python was configured on your machine--you may have to fiddle around for bit basic interpreter operation and setup the following functions are used to set up the interpreter and to run scriptsint pyrun_anyfile(file *fpchar *filenameif fp is an interactive device such as tty in unixthis function calls pyrun_interactiveloop(otherwisepyrun_simplefile(is called filename is lib fl ff