GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sbinet/go-python: naive go bindings to the CPython2 C-API

This repository was archived by the owner on Jul 24, 2023. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

171 Commits
171 Commits

Folders and files

NameName
Last commit message
Last commit date
cmd/go-python
cmd/go-python
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
appveyor.yml
appveyor.yml
 
 
capi.go
capi.go
 
 
cgoflags_unix.go
cgoflags_unix.go
 
 
cgoflags_windows.go
cgoflags_windows.go
 
 
dict.go
dict.go
 
 
exceptions.go
exceptions.go
 
 
exceptions_posix.go
exceptions_posix.go
 
 
file.go
file.go
 
 
gen-cgoflags.go
gen-cgoflags.go
 
 
go-python.c
go-python.c
 
 
go-python.go
go-python.go
 
 
go-python.h
go-python.h
 
 
go.mod
go.mod
 
 
heap.go
heap.go
 
 
init.go
init.go
 
 
init_test.go
init_test.go
 
 
none.go
none.go
 
 
numeric.go
numeric.go
 
 
object.go
object.go
 
 
object_posix.go
object_posix.go
 
 
object_windows.go
object_windows.go
 
 
otherobjects.go
otherobjects.go
 
 
python.go
python.go
 
 
python_test.go
python_test.go
 
 
sequence.go
sequence.go
 
 
type.go
type.go
 
 
utilities.go
utilities.go
 
 
veryhigh.go
veryhigh.go
 
 

Repository files navigation

go-python

sbinet/go-python only supports CPython2. CPython2 isn't supported anymore by python.org. Thus, sbinet/go-python is now archived. A possible alternative may be to use and contribute to go-python/cpy3 instead.

Build Status Build status GoDocs

Naive go bindings towards the C-API of CPython-2.

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 to just look at:

http://docs.python.org/c-api/index.html

and know what to type in your go program.

this package also provides an executable "go-python" which just loads "python" and then call python.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 into go from C through some rather convoluted functions hops)

Install

With Go 1 and the go tool, cgo packages can't pass anymore additional CGO_CFLAGS from external programs (except pkg-config) to the "fake" #cgo preprocessor directive.

go-python now uses pkg-config to get the correct location of headers and libraries. Unfortunately, the naming convention for the pkg-config package is not standardised across distributions and OSes, so you may have to edit the cgoflags.go file accordingly.

 $ go get github.com/sbinet/go-python

If go get + pkg-config failed:

 $ cd go-python
 $ edit cgoflags.go
 $ make VERBOSE=1

Note: you'll need the proper header and python development environment. On Debian, you'll need to install the python-all-dev package

Documentation

Is available on godocs:

https://godocs.io/github.com/sbinet/go-python

Example:

package main

import "fmt"
import "github.com/sbinet/go-python"

func init() {
   err := python.Initialize()
   if err != nil {
          panic(err.Error())
   } 
}

func main() {
 	 gostr := "foo" 
	 pystr := python.PyString_FromString(gostr)
	 str := python.PyString_AsString(pystr)
	 fmt.Println("hello [", str, "]")
}
$ go run ./main.go
hello [ foo ]

TODO:

  • 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 with os.File in "go-python" API

  • provide an easy way to extend go-python with go based extensions

  • think 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

cgogogolangpython2

Resources

Readme
License
Activity

Stars

1.5k stars

Watchers

1 watching

Forks

140 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.