Go to file
Christopher Schmitt 0ae938000d Use GoStringN inside _AsString functions for bytes as they may contain NULLs 2019-11-20 13:37:15 -07:00
.circleci Review 2019-01-29 14:22:32 -07:00
.github Add github templates 2019-01-29 14:22:32 -07:00
examples Add some examples 2019-01-29 14:22:32 -07:00
script Add copyright header 2019-01-29 14:22:32 -07:00
tests Unit tests (#11) 2019-01-29 14:22:32 -07:00
.gitignore Interpreter lifecycle 2018-12-07 14:47:44 -05:00
CONTRIBUTING.md Add github templates 2019-01-29 14:22:32 -07:00
Gopkg.lock Add go test command to the CI (#13) 2018-12-11 09:59:06 -07:00
Gopkg.toml Add go test command to the CI (#13) 2018-12-11 09:59:06 -07:00
LICENSE Initial commit 2018-11-05 13:05:33 -05:00
LICENSE-3rdparty.csv Add LICENSE-3rdparty.csv file 2019-01-29 14:22:32 -07:00
README.md Review 2019-01-29 14:22:32 -07:00
boolean.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
boolean_test.go Add copyright header 2019-01-29 14:22:32 -07:00
byte_array.go Use GoStringN inside _AsString functions for bytes as they may contain NULLs 2019-11-20 13:37:15 -07:00
byte_array_test.go Add copyright header 2019-01-29 14:22:32 -07:00
bytes.go Use GoStringN inside _AsString functions for bytes as they may contain NULLs 2019-11-20 13:37:15 -07:00
bytes_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
complex.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
complex_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
dict.go Fix position type 2019-01-30 15:28:55 -07:00
dict_test.go Add copyright header 2019-01-29 14:22:32 -07:00
errors.go Remove WakeupFd bindings for windows 2019-01-29 14:22:46 -07:00
errors_nix.go Remove WakeupFd bindings for windows 2019-01-29 14:22:46 -07:00
errors_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
exceptions.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
exceptions_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
float.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
float_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
helper.go Add copyright header 2019-01-29 14:22:32 -07:00
high_level_layer.go Add copyright header 2019-01-29 14:22:32 -07:00
high_level_layer_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
import.go Add copyright header 2019-01-29 14:22:32 -07:00
import_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
integer.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
integer_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
lifecycle.go Add copyright header 2019-01-29 14:22:32 -07:00
lifecycle_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
list.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
list_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
macro.c Add copyright header 2019-01-29 14:22:32 -07:00
macro.h Add copyright header 2019-01-29 14:22:32 -07:00
module.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
module_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
object.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
object_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
recursion.go Add copyright header 2019-01-29 14:22:32 -07:00
recursion_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
reflection.go Add copyright header 2019-01-29 14:22:32 -07:00
reflection_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
sys.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
sys_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
thread.go Add copyright header 2019-01-29 14:22:32 -07:00
thread_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
tuple.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
tuple_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
type.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
type_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
unicode.go Don't use non constant in initializer 2019-01-29 14:22:32 -07:00
unicode_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
variadic.c Add copyright header 2019-01-29 14:22:32 -07:00
variadic.h Add copyright header 2019-01-29 14:22:32 -07:00
warning.go Add copyright header 2019-01-29 14:22:32 -07:00
warning_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00

README.md

go-python3

Golang bindings for the C-API of CPython-3.

This package provides a go package named "python" under which most of the PyXYZ functions 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 go program.

Currently supports python-3.7+.

This project was inspired by https://github.com/sbinet/go-python. Go and take a look if we need something for python-2.7!

Install

Simply go get github.com/DataDog/go-python3

Build

We will need pkg-config and a working python3 environment to build these bindings. By default pkg-config will look at the python3 library so if you want to choose a specific version just symlink python-X.Y.pc to python3.pc or use the PKG_CONFIG_PATH environment variable.

API

Some functions mix go code and call to Python function. Those functions will return and int and error type. The int represent the Python result code and the error represent any issue from the Go layer.

Example:

func PyRun_AnyFile(filename string) open filename and 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 int represent the error code from the CPython PyRun_AnyFile function and error will be set if we failed to open filename.

If an error is raise before calling th CPython function int default to -1.

Take a look at some examples