Volver al ranking

sbinet/go-python

Go

naive go bindings to the CPython2 C-API

python2gogolangcgo
Crecimiento de estrellas
Estrellas
1.5k
Forks
140
Crecimiento semanal
Issues
24
5001k1.5k
oct 2012may 2017dic 2021jul 2026
ArtefactosGo Modulesgo get github.com/sbinet/go-python
README

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 ?

Repositorios relacionados
HumanSignal/labelImg

LabelImg is now part of the Label Studio community. The popular image annotation tool created by Tzutalin is no longer actively being developed, but you can check out Label Studio, the open source data labeling tool for images, text, hypertext, audio, video and time-series data.

PythonPyPIMIT Licensepython2python3
youtu.be/p0nR2YsCY_U
25.1k6.6k
Gallopsled/pwntools

CTF framework and exploit development library

PythonPyPIOtherctfexploit
pwntools.com
13.6k1.9k
sammchardy/python-binance

Binance Exchange API python implementation for automated trading

PythonPyPIMIT Licensebinancepython
python-binance.readthedocs.io/en/latest/
7.2k2.3k
mozillazg/python-pinyin

汉字转拼音(pypinyin)

PythonPyPIMIT Licensepythonpinyin
pypinyin.readthedocs.io
5.3k627
PeterDing/iScript

各种脚本 -- 关于 虾米 xiami.com, 百度网盘 pan.baidu.com, 115网盘 115.com, 网易音乐 music.163.com, 百度音乐 music.baidu.com, 360网盘/云盘 yunpan.cn, 视频解析 flvxz.com, bt torrent ↔ magnet, ed2k 搜索, tumblr 图片下载, unzip

PythonPyPIMIT Licensepython2baiduyun
5.1k1.2k
Shpota/github-activity-generator

A script that helps generate a rich GitHub Contribution Graph for your account 🤖

PythonPyPIApache License 2.0pythonpython-script
4.1k413
pyparsing/pyparsing

Python library for creating PEG parsers

PythonPyPIMIT Licensepythonpython2
2.5k317
gabrielfalcao/HTTPretty

Intercept HTTP requests at the Python socket level. Fakes the whole socket module

PythonPyPIMIT Licensehttpmock
httpretty.readthedocs.org
2.2k284
CITGuru/PyInquirer

A Python module for common interactive command line user interfaces

PythonPyPIMIT Licensepythonprompt-toolkit
2k229
simplejson/simplejson

simplejson is a simple, fast, extensible JSON encoder/decoder for Python

PythonPyPIOtherjsonpython
simplejson.readthedocs.io
1.7k354
Lucifer1993/struts-scan

Python2编写的struts2漏洞全版本检测和利用工具

PythonPyPIvulnerability-scannersstruts-exp
1.4k498
NifTK/NiftyNet

[unmaintained] An open-source convolutional neural networks platform for research in medical image analysis and image-guided therapy

PythonPyPIApache License 2.0tensorflowdistributed
niftynet.io
1.4k401