Go bindings to the CPython-3 API
Currently supports python-3.7 only.
Golang bindings for the C-API of CPython-3.
This package provides a
gopackage named "python" under which most of the
PyXYZfunctions and macros of the public C-API of CPython have been exposed. Theoretically, you should be able use https://docs.python.org/3/c-api and know what to type in your
This project was inspired by https://github.com/sbinet/go-python. Go and take a look if we need something for python-2.7!
We will need
pkg-configand a working
python3.7environment to build these bindings. Make sure you have Python libraries and header files installed as well (
python3.7-devon Debian or
python3-develon Centos for example)..
pkg-configwill look at the
python3library so if you want to choose a specific version just symlink
python3.pcor use the
go get github.com/DataDog/go-python3
Some functions mix go code and call to Python function. Those functions will return and
intrepresent the Python result code and the
errorrepresent any issue from the Go layer.
func PyRun_AnyFile(filename string)open
filenameand then call CPython API function
int PyRun_AnyFile(FILE *fp, const char *filename).
Therefore its signature is
func PyRun_AnyFile(filename string) (int, error), the
intrepresent the error code from the CPython
PyRun_AnyFilefunction and error will be set if we failed to open
If an error is raise before calling th CPython function
Take a look at some examples