Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ei-grad/go-pyrun
Run Python code and get result back to Golang
https://github.com/ei-grad/go-pyrun
Last synced: 15 days ago
JSON representation
Run Python code and get result back to Golang
- Host: GitHub
- URL: https://github.com/ei-grad/go-pyrun
- Owner: ei-grad
- License: mit
- Created: 2016-12-06T22:37:11.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-25T14:11:07.000Z (about 8 years ago)
- Last Synced: 2024-11-14T06:06:49.976Z (about 2 months ago)
- Language: Go
- Homepage: https://godoc.org/github.com/ei-grad/go-pyrun
- Size: 7.81 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Go PyRun - simple interactation with Python
===========================================It runs a Python interpreter in single dedicated thread and allows to get
result of Python code evaluation in Golang.[![CircleCI](https://circleci.com/gh/ei-grad/go-pyrun.svg?style=svg)](https://circleci.com/gh/ei-grad/go-pyrun)
Install
-------You would need python-2.7 headers to build and install go-pyrun. On Ubuntu just
install the python2.7-dev package:apt-get install python2.7-dev
Then you should be able to install go-pyrun by `go get`:
go get github.com/ei-grad/go-pyrun
Example
-------```go
package mainimport "github.com/ei-grad/go-pyrun"
import "fmt"
import "log"func main() {
py := pyrun.NewPython()
err := py.Execute(`
def hello():
return 'Hello, world!'
`)
if err != nil {
log.Fatalf("Execute failed: %s", err)
}
ret, err := py.EvalToString("hello()")
if err != nil {
log.Fatalf("EvalToString failed: %s", err)
}
fmt.Printf("Hello from Python: %s\n", ret)
}
```Contributing
------------Feel free to open issues and send pull requests implementing new useful methods.
But it shouldn't be more than a something between a joke and a ducktape for emeregency cases and experimenting.
Look also to @bradfitz's similar module for perl: https://github.com/bradfitz/campher.