Skip to main content

Temporary Python bindings for go-enry language detector

Project description

Python bindings for enry

Python bindings through cFFI (ABI, out-of-line) for calling enry Go functions exposed by CGo wrapper.

Build

# from python/
$ pushd .. && make shared && popd
$ pip install -r requirements.txt
$ python build_enry.py

Builds the Go shared library for the CGo wrapper (libenry.so / libenry.dylib), then generates and builds the CFFI out-of-line module (enry.c) that provides the Python bindings.

Why a shared library?

Historically, the Python package shipped a static library and used CFFI API mode (a compiled extension that links against libenry). That approach relied on Go-generated headers/types (e.g. GoString, GoSlice, and struct return wrappers) and a locally-built archive at build time, which made builds and cross-platform packaging more fragile.

We now build a Go-built shared library (-buildmode=c-shared) that is bundled inside the wheel and loaded via CFFI out-of-line (ABI) mode. This makes installation simpler and allows pip install enry without requiring a Go toolchain.

Implementation note: the shared library is located and loaded at import time in enry/definitions.py (see _load_library()), which prefers the packaged enry/libenry.* shipped in wheels and falls back to local dev build locations.

Future-proof note: if we later change the binding strategy (or revisit linking/packaging), we should reevaluate whether a shared library is still the best tradeoff and update this documentation accordingly.

Installation

From PyPI (Recommended)

For Python 3.9+, install pre-built wheels:

pip install enry

No Go compiler required! Pre-built wheels are available for:

  • Linux: x86_64 (manylinux)
  • macOS: x86_64 (Intel) and arm64 (Apple Silicon)

From Source

If you need to build from source or use an unsupported platform, you'll need Go installed:

git clone https://github.com/go-enry/go-enry.git
cd go-enry
make shared
cd python
pip install -e .

Requirements for building:

  • Go 1.21 or later
  • GCC or compatible C compiler
  • Python 3.9 or later

Developer: publishing to PyPI

Releases are intended to be published from CI on tag pushes (python-v*) using PyPI Trusted Publishing (OIDC).

Note: CI publishing via OIDC is gated on PyPI Trusted Publisher configuration for the enry project (must be set up by a PyPI project owner/maintainer for this repo/workflow).

Until that is configured, you can publish manually using a PyPI API token.

Versioning

Before tagging a release, bump the Python package version in python/pyproject.toml ([project].version) and commit it. The git tag should match the package version (e.g. version = "0.2.1" and tag python-v0.2.1).

Manual publish (recommended): upload CI-built artifacts

This mirrors what the CI does (cibuildwheel builds platform wheels + an sdist). You simply upload the produced artifacts yourself.

  1. Tag a release (this triggers the workflow):
git tag python-vX.Y.Z
git push origin python-vX.Y.Z
  1. Download the workflow artifacts from GitHub Actions:
  • the built wheels (wheels-*)
  • the source distribution (sdist)
  1. Upload with Twine using a PyPI token:
python -m pip install --upgrade twine

# from the directory where you downloaded artifacts:
TWINE_USERNAME=__token__ TWINE_PASSWORD='pypi-***' python -m twine upload **/*.whl **/*.tar.gz

Notes:

  • The token must be created on PyPI by an account with upload permission for the enry project.
  • This approach is preferred because wheels must be built per-platform/per-arch (Linux manylinux + macOS x86_64/arm64).
  • PyPI token notes: set username to token and password to the token value (including the pypi- prefix).

Manual publish (local, single-platform only)

If you only need to build and upload artifacts for your current machine, you should build the Go shared library first (mirrors the CI’s make shared step):

# from repo root: builds and copies libenry.* into python/enry/
make shared

cd python
cp ../LICENSE .
python -m pip install --upgrade build
python -m build --sdist --wheel

python -m pip install --upgrade twine
TWINE_USERNAME=__token__ TWINE_PASSWORD='pypi-***' python -m twine upload dist/*

This requires Go locally and only produces a wheel for the current OS/arch.

Usage

import enry

# Detect language by filename and content
language = enry.get_language("example.py", b"print('Hello, world!')")
print(f"Detected language: {language}")

FFI / API design notes

Some upstream Go enry functions return (value, safe) where safe indicates whether the result is considered unambiguous. The shared library (libenry) exports used by these Python bindings intentionally return only the primary string value and do not currently expose the safe flag.

Rationale: keeping the C ABI to simple primitives (char* in/out + explicit free) avoids returning structs/tuples across the language boundary and reduces ABI + memory-ownership pitfalls. It also keeps the shared library broadly usable by non-Python consumers without committing the core ABI to a particular “safe mode” policy.

Tradeoff: the Python bindings cannot directly access the Go safe signal via the current exports. If we decide we need it, an ABI-friendly extension would be to add parallel exports that surface safety without structs (e.g. ...WithSafety(..., int* out_safe)), while keeping the existing string-only exports for backwards compatibility.

Supported Python Versions

  • Python 3.9+
  • CPython only (PyPy not yet supported)

Note: Python 3.6, 3.7 and 3.8 reached end-of-life and are no longer supported. Use enry 0.1.1 if you must use these versions (not recommended for security reasons).

Platform Support

  • ✅ Linux (x86_64)
  • ✅ macOS (Intel x86_64 and Apple Silicon arm64)
  • ❌ Linux ARM/aarch64 (not yet available)

Known Issues

  • Memory leak fixed in version 0.2.0 (see #36)
  • The current shared-library exports return only a string result and do not expose the Go safe flag (by design; see “FFI / API design notes” above).

Run

Example for single exposed API function is provided.

$ python enry.py

TODOs

  • helpers for sending/receiving Go slices to C
  • read libenry.h and generate ffibuilder.cdef(...) content
  • cover the rest of enry API
  • add setup.py
  • build/release automation on CI (publish on pypi)
  • try ABI mode, to avoid dependency on C compiler on install (+perf test?)

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

enry_python-0.2.0.tar.gz (4.8 MB view details)

Uploaded Source

Built Distributions

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

enry_python-0.2.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

enry_python-0.2.0-cp313-cp313-macosx_11_0_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ x86-64

enry_python-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

enry_python-0.2.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

enry_python-0.2.0-cp312-cp312-macosx_11_0_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ x86-64

enry_python-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

enry_python-0.2.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

enry_python-0.2.0-cp311-cp311-macosx_11_0_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

enry_python-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

enry_python-0.2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

enry_python-0.2.0-cp310-cp310-macosx_11_0_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

enry_python-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

enry_python-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

enry_python-0.2.0-cp39-cp39-macosx_11_0_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

enry_python-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file enry_python-0.2.0.tar.gz.

File metadata

  • Download URL: enry_python-0.2.0.tar.gz
  • Upload date:
  • Size: 4.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for enry_python-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4b61ec7cbf84c4ec46e239135acfcb031607e852141130abee1233e41da5110d
MD5 be0957e59b4187bdc7a7faf1b5046138
BLAKE2b-256 1d79d05c1d771d7741d50d1fd132cc4ae69f9ae7f1aa8647bfd37ebec417a943

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0.tar.gz:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e07739fff339bb769f8f96d92335aae438644cab4f0dfe3c3ac163e829f26b04
MD5 1c19157cc8d3b0cf3b1abb546dadc817
BLAKE2b-256 da6650c26255992b892bee50541fe370ed687b63af5110ce0df77a7da58f91e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp313-cp313-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 b7914a239bdf9a2d0c779c9eb2b50717b7dbe204aa916de6eedc8a01751a90a5
MD5 bc91d64c5436a77c3a356e40754fbe75
BLAKE2b-256 a8297b6778665a4067b6272e69407327a13cc9fbcd1eb3340e8b6ea1bf818fd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp313-cp313-macosx_11_0_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 edcec9e94ba78e790d77483d87347bc08e36a418528b547112810baa8fca6ea2
MD5 5dc87a171a11e75cf4dd6b8ec9e998b9
BLAKE2b-256 2e6e1d30367d78ff458101385a9b69f6b81cf109e89ebc47f4707ac2fa261b7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 193239081280340c1d198daa01cf8966e817e6186c8777301b4b1f52527acd6a
MD5 a52e7df45599b5eec7bb6eee2f3b2fd3
BLAKE2b-256 7fa8f1d3647aa5c89aee7894d2759f7a888e3abdd908b98501eca49cfab3ac83

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp312-cp312-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 8b8b7b800b6ebcbae04a811828e588adebfd1fc19c776a18ef618d5f2411fd8d
MD5 b6c413c8c1c0a5f8e9477a995f5aeec9
BLAKE2b-256 f9236de8b1902e25179c40a06f2956694753ab30427f846dc41861c1eba522fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp312-cp312-macosx_11_0_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ba326a50b1db2fcf2c40a2cf06d43452757185d7ff95c4983a81b131e3bc35e5
MD5 92e539f6aa864559d1f8bc9051f013cf
BLAKE2b-256 4aa988f1861576f467104f06db3af4e658287c05b3b98defe9070a3b269d4d90

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c64cc3d9af972c2743d4eb5bebd434697607a06e115828e276e499912211aa76
MD5 63f1ed6db25c148169896d5384ddb22e
BLAKE2b-256 3d6658e6c779a8fad5e6a66b03844fa4b0d79bdc13c73563160345897f3fcf49

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c7d80f7f315839ee04700f42956b96c73f775d4e7e323534e6219dfca65656c2
MD5 74a0a8c2f5570d928d76608cc23d0f08
BLAKE2b-256 241a5b19ed69a85ef631c37b426c9baf25bbdbad9b7a2c011158b9b923007c1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp311-cp311-macosx_11_0_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 47d0107f26079de4432c73d980ce9203310411d902f0602d43f549617e578d11
MD5 7f48beb58d07bf4c4f1f48ee0650e183
BLAKE2b-256 b7941dcc155e75fb81a6cffe7b47b28209847dcaaf165e481f4b1bf62a0d03d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 593e7aee08e22b5964f5553a63e0f873ff2a3ce5722c8973de4fa4baf5ee81a7
MD5 fa3f1e1b649721b7a72dd039e19e3bea
BLAKE2b-256 c04fd02286f680c4701f5b49b2671b2b0bccf0fd7b4b027f4197458894bfef5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 067d83338529c6f9012c43a3512835be7955a46fe9fc34b4d619637724489ada
MD5 b1867d1e608d9787d4923bb6d49443b1
BLAKE2b-256 2d59df429503b8b83899983131cee8251f9d7e8594fb7279d623571b4c034175

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp310-cp310-macosx_11_0_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a1d05c3a441c50fa1e1b3d59e00f72b51b500d51b06459fe25f3040f6caa116d
MD5 3bc382814008f0bc022d32ae2392f895
BLAKE2b-256 f695777ac7f7a44a3b609a743fc520336657041c2f6ff16bab3a77cbbc2f0040

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 de758237c68a01d1f3ae09350806b00173be473fc3b5418c2006ceb0b1a4d28d
MD5 4111f1bc6184d15f81eb4b2391490fe8
BLAKE2b-256 ccb4351d08645076d8c95303c5d154fccb8c443b6bb2a184121fd8d8f763ed3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 d7a0b8ddc1fc6521afd652a1e1c7333925515a5e61e15b88055f3602ecf8fa8d
MD5 b645d87caa4973f0b8e1535dfd28a5b1
BLAKE2b-256 e27c5111397c368ac847a014f59c969d45015b49f54f8aaa21406c2758f8cad4

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp39-cp39-macosx_11_0_x86_64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file enry_python-0.2.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for enry_python-0.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f506e6ad3c7f92edc50ac5f2283fc300dfde54b23777dedd5176e57405c23669
MD5 8c8240b09b26fd00443f3df61f129c62
BLAKE2b-256 8e3aca295e0cb4386995b542cd02d0521bee5b292c9a0b6843a5dae4c0e45cfc

See more details on using hashes here.

Provenance

The following attestation bundles were made for enry_python-0.2.0-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on Esoiya/go-enry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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