• This repository has been archived on 24/Jul/2023
  • Stars
    star
    1,510
  • Rank 29,884 (Top 0.7 %)
  • Language
    Go
  • License
    Other
  • Created almost 12 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

naive go bindings to the CPython2 C-API

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 ?

More Repositories

1

igo

A simple interactive Go interpreter built on go-eval with some readline-like refinements
Go
649
star
2

go-eval

the beginning of an interpreter for Go (fork off exp/eval)
Go
342
star
3

perfbook

mirror of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git
C
72
star
4

go-clang

DEPRECATED. use https://github.com/go-clang. CGo bindings to the C-api of libclang.
C
53
star
5

npyio

npyio provides read/write access to numpy data files.
Go
53
star
6

go-hdf5

**DEPRECATED** Go bindings to the HDF5 library
Go
44
star
7

go-ffi

an experimental package to use libffi from Go.
Go
40
star
8

notes-and-todos

notes about stuff
39
star
9

wasm

tools to interact with WASM files
Go
36
star
10

pstree

a simple API to retrieve a process tree
Go
29
star
11

pygo

A WIP toy interpreter in Go, for CPython
Go
28
star
12

go-gnuplot

naive go bindings to GnuPlot
Go
27
star
13

margo

Marvelous Go tutorial
Go
20
star
14

go-cxxdict

Tools to automatically generate Go bindings for C/C++ libraries from GCC-XML informations. fork from genreflex from root.cern.ch to add go-bindings.
Go
18
star
15

go-web-examples

a set of simple (and not so simple) web-servers written in Go
Go
14
star
16

go-svn2git

Go tool for importing existing svn projects into git.
Go
12
star
17

plugs

plugs compiles and loads Go plugins.
Go
11
star
18

jdev-go-datascience-2017

DataScience intro with Go for the JDEV-2017
Go
10
star
19

present-tex

WIP: create LaTeX/Beamer slides from present
Go
9
star
20

iview

A minimalistic image viewer written in Go.
Go
9
star
21

talks

my (work related) talks+papers, over the years
TeX
8
star
22

go-root

an experimental pure-Go library to read ROOT files w/o ROOT.
Go
8
star
23

img-diff

Go
8
star
24

go-imap

git mirror of http://code.google.com/p/go-imap/
Go
8
star
25

go-trackml

trackml is a Go package to simplify working with the High Energy Physics Tracking Machine Learning challenge
Go
7
star
26

pmon

pmon is a process wrapper for (simple) resource monitoring.
Go
7
star
27

mk

`mk` is a simple `make` like command to ease the day-to-day life of building and testing `go` based projects.
Go
7
star
28

go-readline

bind more of the readline API (based on python's readline module)
Go
6
star
29

go-android

NDK bindings for Android and Go
Go
5
star
30

go-config

Configuration file parser for INI format
Go
5
star
31

goctogit

giving git more tentacles (in go)
Go
5
star
32

install-go

``install-go`` is a simple script to install a given ``Go`` toolchain for a given set of ``linux`` platforms.
Go
4
star
33

go-arff

go-arff is a simple pure-Go package to read and write Attribute-Relation File Format (ARFF) data files
Go
4
star
34

covid19

A small web server to display COVID-19 related data
Go
4
star
35

matfio

Read/Write access to MATLAB files from `Go`
Go
3
star
36

go-root2pb

An experimental tool to generate .proto files from ROOT TTrees.
Go
3
star
37

go2-test

Go
3
star
38

fs-watch

Go
3
star
39

go-terminal

a fork of code.google.com/p/go.crypto/ssh/terminal to test a few things (history, and few other callbacks goodies)
Go
3
star
40

cern-sso

cern-sso provides tools to authenticate with CERN tools via SSO
Go
3
star
41

atl-cvmfs

atl-cvmfs is a simple command to create, install and remove athena package tarballs off a CVMFs repository
Go
3
star
42

go-cblas

Go bindings to CBLAS
Go
2
star
43

go-pb-example

simple protobuf example for go
Go
2
star
44

margo-2017

Go
2
star
45

isbn

isbn scans ISBN barcode images
Go
2
star
46

iml-workshop-2017

A simple repository for the IMLWorkshop-2017 challenge
Go
2
star
47

auto-vectorization

playground for autovectorization (C, C++ and Go)
2
star
48

goxx

goxx is a TEMPORARY snapshot of the official go tool.
Go
2
star
49

go-hep

A (set of) Go packages for High Energy Physics
Go
2
star
50

stickytasks

Package to stick tasks to goroutines to ensure ordered processing
Go
2
star
51

rootjs-serve

a simple web server for JSROOT
Go
2
star
52

ji-2014-go

repository for the JI-2014 and the Go hands-on
Go
2
star
53

go-drillbit

go-drillbit is a WIP go implementation of drillbit
Go
2
star
54

fubsy

mirror of hg.gerg.ca/fubsy: the universal build tool
Go
2
star
55

advent-of-code

Code for http://adventofcode.com
Go
2
star
56

docker-containers

**DEPRECATED** A set of scripts and Dockerfile files to create and manage docker images.
Shell
2
star
57

croot

a simple work-in-progress C-API binding to the C++ ROOT framework.
C++
2
star
58

cmark

a simple web server to convert markdown files
Go
2
star
59

gridka-go-2017

Slides and exercizes for the GridKa Go Workshop
Go
1
star
60

mozcookie

mozcookie reads and writes files in the Mozilla/Netscape HTTP Cookie File format
Go
1
star
61

clang-cms

clang-cms is a clang plugin from the CMS experiment to check for MT code smells
C++
1
star
62

go-higgsml

a simple starting kit for the HiggsML challenge, in Go.
Go
1
star
63

blog

Sources for my github-backed blog/website
Go
1
star
64

gridka-go-2016

Slides and exercizes for the GridKa Go Workshop
Go
1
star
65

ji-go-adv-2016

Go
1
star
66

sirhus-view

Simple web application to ease the creation of "Dossiers Annuels" in Sirhus
Go
1
star
67

rse-conf-go-2016

Go
1
star
68

go-plugin

go-plugin: a testbed for `plugin`
Go
1
star
69

fstf

C++
1
star
70

go-gaudi

an experimental mock-up gaudi framework in go-lang
Go
1
star
71

gh-mv-issues

gh-repo-mv migrates github repositories from one place to the other
Go
1
star
72

go-tucs

An experimental re-write of TUCS (TileCal Unified Calibration Software) in Go
Go
1
star
73

gridka-go-tuto

Go
1
star
74

go-gnuflag

mirror of launchpad.net/gnuflag
Go
1
star
75

vego

a pure-Go implementation of vega
Go
1
star
76

notmuch

Notmuch is not much of an email program
C
1
star
77

atl-jira

atl-jira is a naive command interface client to JIRA REST API.
Go
1
star
78

binder-go

Jupyter Notebook
1
star
79

go-types

types from exp/types
Go
1
star
80

ccin2p3-2017-go

tuto for go@CC-IN2P3
Go
1
star
81

go-croot

Go bindings to the C-API of ROOT.
Go
1
star