Skip to content
This repository has been archived by the owner on Nov 21, 2018. It is now read-only.
/ gothon Public archive

Python 3.6+ modules written on pure Go 1.10+. No CFFI, no CTypes, no CGo, no PyBindGen, just import *.go files from Python.

License

Notifications You must be signed in to change notification settings

juancarlospaco/gothon

Gothon

Python 3 modules written on pure Go. No CFFI, no CTypes, no CGo, no PyBindGen, just import *.go files from Python.

It works using RPC. Inspired by Cythons pyximport and CPPImport. Designed to speed up Python using Go. Build Status

Open Repo access to anyone who want to contribute, just contact me.

screenshot

Use

$ ls
gothon.py  python_module.go

$ python
Python 3.6.4 (default, Jan  5 2018, 02:35:40)

>>> import gothon                   # Import & enable Gothon.
>>> gothon.import_hook()
>>> import python_module            # Import *.go files.
>>> repr(python_module)
'<Gothon object 140066220608272 from python_module.go>'
>>> python_module.__doc__
'Gothon runs GO Code from Python using IPC RPC JSON.'
>>> worker = python_module.start()
>>> worker.call("Echo.Echo", "Hello from Python to Go")
'Hello from Python to Go'
>>>

Install

pip install gothon
  • No dependencies, it does not install any Python dependency nor Go dependency.
  • Uninstall pip uninstall gothon

Documentation

gothon.Gothon()

Description: Gothon runs GO Code from Python using IPC RPC JSON.

Delegates the Parse, Compile, Build and Cache to Go itself.

If you Upgrade your Go version you dont have to change anything on Gothon, it just works.

If you Upgrade your Python version you dont have to change anything on Gothon, it just works.

Unix Socket are used because from benchmarks it performs 3x faster than TCP/UDP Sockets.

This does not connect to the network, nor internet, nor use HTTP.

This project is oriented to Developers, NOT end-users.

This project can be used with Fades, FireJails, Docker, RKT.

This project assumes at least very basic knowledge of the Go programming language.

Its recommended to have 1 *.go file importable from Python for project or package, the *.go file itself can import Go functions from other *.go files using Go way of importing stuff.

Feel free to contact us if you need help integrating it on your project.

Arguments:

  • go_file A GO file to compile and run as a python module, str or pathlib.Path type, defaults to python_module.go, required.
  • startup_delay A startup delay, after building the go file but before returning the IPC RPC to Python, float type, defaults to 0.1, can be set to 0.0 too, can not be None, optional.

Keyword Arguments: None.

Returns: gothon.RPCJSONClient() an custom IPC RPC.

Base Class: object.

Type: object.

Source Code file: https://github.com/juancarlospaco/gothon/blob/master/gothon.py

State OS Description
Linux Works Ok
Os X Works Ok

Usage Example:

>>> from gothon import Gothon
>>> unemployed = Gothon()
>>> worker = unemployed.start()
>>> worker.call("Echo.Echo", "Hello from Python to Go")
'Hello from Python to Go'
>>> worker.stop()
>>>

Helper Static Methods:

  • gothon.Gothon().template()

Prints to standard output a Go source code template to start hacking into, with all bits and pieces to write a Python module using Go, it has 1 "Echo" function that you can overwrite or delete, this Go source code is ready to run as-is.

  • gothon.Gothon().clean()

Clean up the Cache, uses glob.iglob() and pathlib.Path().unlink(), its very fast.

Requisites

Troubleshoot
Not working
  • Delete all __pycache__ and *.pyc.
  • Execute go clean -x -cache (Usually Go takes care of cleaning Cache automatically).
  • Update your Go to the latest version.

Why

Things that Ive tried and didnt work (2018, Linux):

Contributors

  • This project welcomes all Python and Go developers.
  • Please Star this Repo on Github !, it helps to show up faster on searchs.
  • Help and more Help and Interactive Quick Git Tutorial.
  • English is the primary default spoken language, unless explicitly stated otherwise (eg. Dont send Translation Pull Request)
  • Pull Requests for working passing unittests welcomed.

Licence

  • BSD.

Ethics and Humanism Policy

  • Religions is not allowed. Contributing means you agree with the COC.

About

Python 3.6+ modules written on pure Go 1.10+. No CFFI, no CTypes, no CGo, no PyBindGen, just import *.go files from Python.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published