- Notifications
You must be signed in to change notification settings - Fork139
naive go bindings to the CPython2 C-API
License
sbinet/go-python
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
sbinet/go-python
only supports CPython2. CPython2 isn't supported anymore bypython.org. Thus,sbinet/go-python
is now archived.A possible alternative may be to use and contribute togo-python/cpy3 instead.
Naivego
bindings towards the C-API of CPython-2.
this package provides ago
package named "python" under which most of thePyXYZ
functions and macros of the public C-API of CPython have been exposed.
theoretically, you should be able to just look at:
http://docs.python.org/c-api/index.html
and know what to type in yourgo
program.
this package also provides an executable "go-python" which just loads "python" and then callpython.Py_Main(os.Args)
.the rational being that under such an executable,go
based extensions for C-Python would be easier to implement (as this usually means calling intogo
fromC
through some rather convoluted functions hops)
WithGo 1
and thego
tool,cgo
packages can't pass anymoreadditionalCGO_CFLAGS
from external programs (exceptpkg-config
)to the "fake"#cgo
preprocessor directive.
go-python
now usespkg-config
to get the correct location ofheaders and libraries.Unfortunately, the naming convention for thepkg-config
package isnot standardised across distributions and OSes, so you may have toedit thecgoflags.go
file accordingly.
$ go get github.com/sbinet/go-python
Ifgo get
+pkg-config
failed:
$cd go-python $ edit cgoflags.go $ make VERBOSE=1
Note: you'll need the proper header andpython
development environment. On Debian, you'll need to install thepython-all-dev
package
Is available ongodocs
:
https://godocs.io/github.com/sbinet/go-python
package mainimport"fmt"import"github.com/sbinet/go-python"funcinit() {err:=python.Initialize()iferr!=nil {panic(err.Error()) } }funcmain() {gostr:="foo"pystr:=python.PyString_FromString(gostr)str:=python.PyString_AsString(pystr)fmt.Println("hello [",str,"]")}
$ go run ./main.gohello [ foo ]
fix handling of integers (I did a poor job at making sure everything was ok)
add CPython unit-tests
do not expose
C.FILE
pointer and replace it withos.File
in "go-python" APIprovide an easy way to extend go-python with
go
based extensionsthink about the need (or not) to translate CPython exceptions into go panic/recover mechanism
use SWIG to automatically wrap the whole CPython api ?
About
naive go bindings to the CPython2 C-API
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.