Skip to main content
# 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 IPC RPC. Inspired by [Cythons `pyximport`](http://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html?highlight=pyximport#pyximport-cython-compilation-for-developers) and [CPPImport](https://github.com/tbenthompson/cppimport#import-c-or-c-files-directly-from-python). Designed to speed up Python using Go.

Open Repo access to anyone who want to contribute, just contact me. **This is a Work In Progress.**

![screenshot](https://source.unsplash.com/FqkBXo2Nkq0/850x420 "Illustrative Photo by https://unsplash.com/@stickermule")


# Use

```python
$ 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
```
- Uninstall `pip uninstall gothon`


# Documentation

<details>
<summary><b>gothon.py</b></summary>

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

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.

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

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.

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, string 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`, 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 |
| ------------------ |:-----------:| -----------:|
| :white_check_mark: | **Linux** | Works Ok |
| :white_check_mark: | **Os X** | Works Ok |

**Usage Example:**

```python
>>> 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()
>>>
```

</details>


# Requisites

- [Python 3.6+](https://python.org)
- [Go 1.10+](https://golang.org)


##### Troubleshoot

<details>
<summary>Not working</summary>

- 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.
</details>


# Why

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

- https://blog.filippo.io/building-python-modules-with-go-1-5/ (Go 1.5 only)
- https://github.com/go-python/gopy/issues/83 (Python 2 only)
- https://github.com/go-python/gopy/blob/master/gen.go#L81 (Python 2 only)
- https://github.com/sbinet/go-python (Python 2 only)
- https://dustymabe.com/2016/09/13/sharing-a-go-library-to-python-using-cffi/ (Compiler Errors on embebed obfuscated C)
- http://pybindgen.readthedocs.io/en/latest/tutorial/#supported-python-versions (Compiler Errors on obfuscated C)
- https://hackernoon.com/extending-python-3-in-go-78f3a69552ac (All of the above)
- Other solutions call Python from Go, the reverse of Gothon.
- Others I dont remember the links.


### Contributors

- **Please Star this Repo on Github !**, it helps to show up faster on searchs.
- [Help](https://help.github.com/articles/using-pull-requests) and more [Help](https://help.github.com/articles/fork-a-repo) and Interactive Quick [Git Tutorial](https://try.github.io).
- 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.

Metadata

Release files for gothon 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gothon 0.5.0
File Size Uploaded Provenance
gothon-0.5.0.zip 13.1 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for gothon 0.5.0
File Interpreter ABI Platform
gothon-0.5.0-py3.6.egg Legacy Egg format - - Details
gothon-0.5.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 30.3 kB

Release files / gothon-0.5.0.zip

Download URL gothon-0.5.0.zip
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f0059c4d669f518822fa4497de1aa742c81ed60c08e8a4ef3f7efaf2ebd92618
BLAKE2b-256 checksum
How to use checksums
d7df1ed663351fe29a15cf7a7f6b44a80510677c27196dd2fc95c85cbfa3bfd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / gothon-0.5.0-py3.6.egg

Download URL gothon-0.5.0-py3.6.egg
Size 7.1 kB
Tags Egg
SHA-256 checksum
How to use checksums
f04126f31d46ebb742394b0e67e0ddf6ed6478cb430bccbad0f0bf0d6c62c18a
BLAKE2b-256 checksum
How to use checksums
9ac00969cc4e66c349075dfe3910a65657b408040ed4a0be9e73af218be53acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / gothon-0.5.0-py2.py3-none-any.whl

Download URL gothon-0.5.0-py2.py3-none-any.whl
Size 10.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c3e3273052de0f7eecc6139e2ad8b15521b1fdb27f28141d2d3dbae67f6028a8
BLAKE2b-256 checksum
How to use checksums
cc0f23c9511b671ab63cb8bdfcfe1fa747039dcfe4207971133de6a5e7e9e00b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for gothon 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.5.0 This release

3 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page