Skip to main content

Add your description here

Project description

go4py: ⚡ Supercharge your Python with Go ⚡

Do you ever wish Python were faster? go4py is here to help! Enjoy the speed and simplicity of Go within Python! You can write bottlenecks of your Python code as CGo functions. The go4py will automatically generate a Python module from it for you!

Check the performance boost in our benchmarks and get a sense of how much faster it can be compared to basic Python! 🚀

Installation

Linux

  1. Install Go
  2. pip install go4py

Windows

  1. Install Go
  2. Install MSYS2 and then install mingw-toolchain inside it.
  3. Install go4py in a python vitrual exnvironment.
  4. Open a mingw shell and activate the venv inside it (e.g. source venv/Scripts/activate)
  5. Add Go to your PATH in the mingw shell (e.g., export PATH=$PATH:"/c/Program Files/Go/bin/")

Usage

To create a Go package inside your Python project:

 go4py init <module_name>

This will create a directory with the name <module_name> and add go.mod to your project. You can go to <module_name>/src directory and add your Go functions there.

To build the Go package and generate bindings code for the Python module:

 go4py build <module_name>

You can now import the functions as methods of a python module:

from <module_name> import <function_name>

Please note that we convert the function names' first character to lower case.

How it works

There is a Makefile in the created directory with four major steps:

  1. Parsing the Go code and extracting the signatures of the functions (the functions.json file).
  2. Building an object file from Go code (.a and .h files).
  3. Making a C wrapper for the Go functions as a Python native C extension.
  4. Building a shared library from the generated C code (__init__.so file or __init__.pyd file).

The Makefile is actually quite readable, and you can modify it to your needs go4py will just run it

Documentation

This documentation will explain how to use go4py. there is also a examples directory for some examples. But if you need to dive into inner-workings of go4py take a look at the tests directory and checkout the codes that go4py generates automaticly from a go function signature.

TODO

  • Windows support
  • no-GIL mode
  • custom user bindings code
  • make a helper function in go for passing Go slices to C
  • documentation
  • read the pakage .h file to check if function name is found there.
  • Generate type definitions file (.pyi file).
  • Can we make async Python functions or not?
  • Warn the user if it uses string or other dynamically allocated types as a result.
  • Warn the user for an unexported function or wrong export with space (// export).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

go4py-0.1.73.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

go4py-0.1.73-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file go4py-0.1.73.tar.gz.

File metadata

  • Download URL: go4py-0.1.73.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for go4py-0.1.73.tar.gz
Algorithm Hash digest
SHA256 c016770033ca1e9d92839505d6a8a6bfbedb3fa3a9c33c1f68352040cdbdff23
MD5 88b654a287be61da153e0cc9954eec04
BLAKE2b-256 04efe3eb0945f4554259e418e415dcf64ebc5cfc844db9798db9463adac7fe27

See more details on using hashes here.

File details

Details for the file go4py-0.1.73-py3-none-any.whl.

File metadata

  • Download URL: go4py-0.1.73-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for go4py-0.1.73-py3-none-any.whl
Algorithm Hash digest
SHA256 052ed489a49dd25faf741ca797374c851a6d8b2d7f35aa8f7e0a6cd84a1a6288
MD5 fe552acad1f26388fc804029783ac35d
BLAKE2b-256 43ff2fe724bc5e663fd1bbd824a5574a6a903755b6e6cf81b69c8df2364a3744

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page