Embedding Python in C

Barry Scott barry at barrys-emacs.org
Wed Jul 17 13:54:33 EDT 2019



> On 17 Jul 2019, at 16:57, jesse.ibarra.1996 at gmail.com wrote:
> 
> I am using Python3.6:
> 
> [jibarra at redsky ~]$ python3.6
> Python 3.6.8 (default, Apr 25 2019, 21:02:35) 
> [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> 
> 
> I am referencing:https://docs.python.org/3.6/extending/embedding.html#beyond-very-high-level-embedding-an-overview
> 
> Is there a way to call a shared C lib using PyObjects?

If what you want to call is simple enough then you can use the ctypes library
that ships with python.

If the code you want to call is more complex you will want to use one of a number of libraries to help
you create a module that you can import.

I use PyCXX for this purpose that allows me to write C++ code that can call C++ and C libs and interface
easily with python. Home page http://cxx.sourceforge.net/ <http://cxx.sourceforge.net/> the source kit contains demo code that you shows
how to cerate a module, a class and function etc. 

Example code: https://sourceforge.net/p/cxx/code/HEAD/tree/trunk/CXX/Demo/Python3/simple.cxx <https://sourceforge.net/p/cxx/code/HEAD/tree/trunk/CXX/Demo/Python3/simple.cxx>

Barry
PyCXX maintainer

> 
> Please advise.
> 
> Thank you.
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list