Python runtime + builder for calling Go shared libraries directly (MessagePack ABI).
Project description
usegolib
Call Go libraries from Python by loading a Go-built shared library directly into the Python process.
- No C/C++ glue code written by you
- No background Go process (no daemon / RPC / subprocess)
- MessagePack-based ABI with manifest-driven schema validation
Status
usegolib is early-stage software (v0.x). Expect sharp edges and evolving interfaces.
How It Works
- Build time (CI / build machine): use the Go toolchain plus an auto-provisioned C compiler (Zig) to build a Go module into a shared library and emit
manifest.json. - Runtime (end-user / production): Python loads the shared library and calls it via MessagePack. No daemon, no RPC, no subprocess.
Requirements
- Python 3.10+
- Go toolchain
- required for building artifacts (CI / build machine)
- required in dev if you rely on auto-build (missing artifact triggers a build)
- not required for end-user runtime if you ship prebuilt artifacts or wheels
Installation
python -m pip install usegolib
From source (dev):
python -m pip install -e ".[dev]"
Quickstart
Build an artifact from a local Go module directory:
usegolib build --module path/to/go/module --out out/artifact
Import from the artifact root and call exported functions:
import usegolib
h = usegolib.import_("example.com/mod", artifact_dir="out/artifact")
print(h.AddInt(1, 2))
Dev convenience: omit artifact_dir to use the default artifact cache root. If the artifact
is missing, usegolib.import_ will build it into the default cache when a Go toolchain is
available.
import usegolib
h = usegolib.import_("example.com/mod")
print(h.AddInt(1, 2))
To enforce "no build" behavior, pass an explicit artifact root and set build_if_missing=False:
import usegolib
h = usegolib.import_("example.com/mod", artifact_dir="out/artifact", build_if_missing=False)
Example: Calling Insyra From Python
Insyra is a Go data-analysis library: github.com/HazelnutParadise/insyra.
Auto-build on import (developer convenience; downloads the module + builds into usegolib's default artifact root):
import usegolib
insyra = usegolib.import_("github.com/HazelnutParadise/insyra", version="v0.2.14")
# DataList (object handle + variadic any)
dl = insyra.NewDataList()
dl.Append(1, 2, 3, 4, 5)
print(dl.Sum(), dl.Mean())
# DataTable (variadic map[string]any + variadic bool)
dt = insyra.NewDataTable()
dt.AppendRowsByColIndex({"A": 1, "B": 2}, {"A": 3, "B": 4})
print(dt.NumRows(), dt.NumCols())
dt.Show()
Notes:
usegolibcan only call functions/methods whose parameter and return types are supported by the current type bridge (seedocs/abi.md).- This example requires a Go toolchain to be installed. (At the time of writing,
insyra@v0.2.14requiresgo >= 1.25and may cause Go to auto-download a newer toolchain.) - If you want to disable auto-build, pass
build_if_missing=False(and usually an explicitartifact_dir). - For end-users without Go, ship prebuilt artifacts/wheels (see Packaging).
Methods (Object Handles)
For exported methods, usegolib supports Go-side object handles (opaque ids) to avoid serializing the receiver on every call:
with h.object("Counter", {"n": 1}) as c:
print(c.Inc(2))
Typed object handles (schema required):
th = h.typed()
types = th.types
with th.object("Counter", types.Counter(N=10)) as c:
snap = c.Snapshot()
print(snap)
Generic Functions (Build-Time Instantiation)
Generic functions require explicit build-time instantiation:
usegolib build --module example.com/mod --out out/artifact --generics generics.json
At runtime (schema required), use the helper:
fn = h.generic("Id", ["int64"])
print(fn(123))
Packaging (Ship Wheels Without Requiring Go)
Generate a distributable Python package project embedding artifacts:
usegolib package --module path/to/go/module --python-package-name mypkg --out out/
Install the generated project:
python -m pip install -e out/mypkg
import mypkg
print(mypkg.AddInt(1, 2))
Version Rules
- One Go module = one version per Python process
- If a module is already loaded, all subpackages must use the same version
- If
version=Noneand multiple artifact versions exist underartifact_dir, import fails withAmbiguousArtifactError(unless that module is already loaded in the current process, in which caseversion=Nonefollows the already-loaded version)
Documentation
docs/roadmap.mddocs/abi.mddocs/cli.mddocs/versioning.mddocs/compatibility.mddocs/testing.mddocs/security.mddocs/troubleshooting.mddocs/releasing.md
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file usegolib-0.1.0.tar.gz.
File metadata
- Download URL: usegolib-0.1.0.tar.gz
- Upload date:
- Size: 75.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f1d47d9c3453c5f2c5d3352cc8214ef56406ffd730ff43a3859b61bae0ffbbb
|
|
| MD5 |
5fc732ab37b391d4c4a63c109e76176f
|
|
| BLAKE2b-256 |
8a8d9d7b96e163a93da60f9f214988715e2580c3832435fd3ccf943148058f28
|
Provenance
The following attestation bundles were made for usegolib-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on TimLai666/usegolib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
usegolib-0.1.0.tar.gz -
Subject digest:
2f1d47d9c3453c5f2c5d3352cc8214ef56406ffd730ff43a3859b61bae0ffbbb - Sigstore transparency entry: 938058813
- Sigstore integration time:
-
Permalink:
TimLai666/usegolib@2cedbc1ee11d7da15cd33f7673d619eefec97ed1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TimLai666
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2cedbc1ee11d7da15cd33f7673d619eefec97ed1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file usegolib-0.1.0-py3-none-any.whl.
File metadata
- Download URL: usegolib-0.1.0-py3-none-any.whl
- Upload date:
- Size: 64.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7dc7226ce82deaac463964e183f5f571e54ba39d0f10e03ecf8451e22720d58
|
|
| MD5 |
325121c189c943c62a97119db82c068d
|
|
| BLAKE2b-256 |
a3772659a942d1a9c7290640769d09390527cd33eecef206738e495cd9d26a37
|
Provenance
The following attestation bundles were made for usegolib-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on TimLai666/usegolib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
usegolib-0.1.0-py3-none-any.whl -
Subject digest:
d7dc7226ce82deaac463964e183f5f571e54ba39d0f10e03ecf8451e22720d58 - Sigstore transparency entry: 938058817
- Sigstore integration time:
-
Permalink:
TimLai666/usegolib@2cedbc1ee11d7da15cd33f7673d619eefec97ed1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TimLai666
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2cedbc1ee11d7da15cd33f7673d619eefec97ed1 -
Trigger Event:
workflow_dispatch
-
Statement type: