Go to file
Stein Ivar Berghei 7d65f97b9f Update 2023-05-24 17:30:48 +09:00
.circleci rename project to github.com/go-python/cpy3 2021-10-24 14:08:10 +02:00
.github Add github templates 2019-01-29 14:22:32 -07:00
examples rename project to github.com/go-python/cpy3 2021-10-24 14:08:10 +02:00
script rename project to github.com/go-python/cpy3 2021-10-24 14:08:10 +02:00
tests Unit tests (#11) 2019-01-29 14:22:32 -07:00
.gitignore add .vscode to gitignore 2021-10-24 13:55:07 +02:00
CONTRIBUTING.md rename project to github.com/go-python/cpy3 2021-10-24 14:08:10 +02: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 rename project to github.com/go-python/cpy3 2021-10-24 14:08:10 +02:00
LICENSE-3rdparty.csv Add LICENSE-3rdparty.csv file 2019-01-29 14:22:32 -07:00
README.md add Slack link 2021-10-25 23:40:23 +02:00
boolean.go Update 2023-05-24 17:30:48 +09:00
boolean_test.go Actually template the license 2021-08-05 11:47:52 +01:00
byte_array.go Update 2023-05-24 17:30:48 +09:00
byte_array_test.go Actually template the license 2021-08-05 11:47:52 +01:00
bytes.go Update 2023-05-24 17:30:48 +09:00
bytes_test.go Actually template the license 2021-08-05 11:47:52 +01:00
complex.go Update 2023-05-24 17:30:48 +09:00
complex_test.go Actually template the license 2021-08-05 11:47:52 +01:00
dict.go Update 2023-05-24 17:30:48 +09:00
dict_test.go Actually template the license 2021-08-05 11:47:52 +01:00
errors.go Actually template the license 2021-08-05 11:47:52 +01:00
errors_nix.go Actually template the license 2021-08-05 11:47:52 +01:00
errors_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
exceptions.go Actually template the license 2021-08-05 11:47:52 +01:00
exceptions_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
float.go Update 2023-05-24 17:30:48 +09:00
float_test.go Actually template the license 2021-08-05 11:47:52 +01:00
go.mod Update 2023-05-24 17:30:48 +09:00
go.sum Update 2023-05-24 17:30:48 +09:00
helper.go Actually template the license 2021-08-05 11:47:52 +01:00
high_level_layer.go Actually template the license 2021-08-05 11:47:52 +01:00
high_level_layer_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
import.go Actually template the license 2021-08-05 11:47:52 +01:00
import_test.go Actually template the license 2021-08-05 11:47:52 +01:00
integer.go Actually template the license 2021-08-05 11:47:52 +01:00
integer_test.go Actually template the license 2021-08-05 11:47:52 +01:00
lifecycle.go Actually template the license 2021-08-05 11:47:52 +01:00
lifecycle_test.go Actually template the license 2021-08-05 11:47:52 +01:00
list.go Update 2023-05-24 17:30:48 +09:00
list_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
macro.c Actually template the license 2021-08-05 11:47:52 +01:00
macro.h Actually template the license 2021-08-05 11:47:52 +01:00
module.go Actually template the license 2021-08-05 11:47:52 +01:00
module_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
object.go Actually template the license 2021-08-05 11:47:52 +01:00
object_test.go Actually template the license 2021-08-05 11:47:52 +01:00
recursion.go fix Py_EnterRecursiveCall C.free sequence 2021-10-08 11:06:40 +02:00
recursion_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
reflection.go Actually template the license 2021-08-05 11:47:52 +01:00
reflection_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
sys.go Update 2023-05-24 17:30:48 +09:00
sys_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
thread.go Update 2023-05-24 17:30:48 +09:00
thread_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
tuple.go Actually template the license 2021-08-05 11:47:52 +01:00
tuple_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
type.go Actually template the license 2021-08-05 11:47:52 +01:00
type_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
unicode.go Actually template the license 2021-08-05 11:47:52 +01:00
unicode_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00
variadic.c Actually template the license 2021-08-05 11:47:52 +01:00
variadic.h Actually template the license 2021-08-05 11:47:52 +01:00
warning.go Actually template the license 2021-08-05 11:47:52 +01:00
warning_test.go Unit tests (#11) 2019-01-29 14:22:32 -07:00

README.md

Go bindings for the CPython-3 C-API

Currently supports python-3.7 only.

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.

relation to DataDog/go-python3

This project is a community maintained successor to DataDog/go-python3, which will get archived in December 2021.

  • If you use the Go package github.com/DataDog/go-python3 in your code, you can use github.com/go-python/cpy3 as a drop-in replacement. We intend to not introduce breaking changes.
  • If you have unmerged PRs or open issues on DataDog/go-python3, please re-submit them here.

relation to sbinet/go-python

This project was inspired by sbinet/go-python (Go bindings for the CPython-2 C-API).

Install

Deps

We will need pkg-config and a working python3.7 environment to build these bindings. Make sure you have Python libraries and header files installed as well (python3.7-dev on Debian or python3-devel on Centos for example)..

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.

Go get

Then simply go get github.com/go-python/cpy3

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 and this tutorial blogpost.

Contributing

Contributions are welcome! See details.

Community

Find us in #go-python on Gophers Slack. (infos | invite)

This project follows the Go Community Code of Conduct.