Distributing Go binaries like sqlite-scanner through PyPI using go-to-wheel
Summary
The article introduces `go-to-wheel`, a new tool designed to simplify the distribution of Go binaries via PyPI, enabling them to be installed and managed like Python packages. This approach allows Go command-line interface (CLI) tools, such as the `sqlite-scanner` utility for finding SQLite database files, to be easily installed using `pip install` or `uvx`. The `sqlite-scanner` tool identifies SQLite files by their `SQLite format 3\x00` magic number, supports concurrent scanning, and outputs results in plain text, JSON, or newline-delimited JSON. The distribution mechanism leverages Python's packaging system to deliver architecture-specific `.whl` files, containing the Go binary and a Python wrapper that executes it. This method facilitates using Go binaries as dependencies within Python projects, as demonstrated by `datasette-scan`, a Datasette plugin that utilizes `sqlite-scanner` to attach found databases.
Key takeaway
For Python developers building tools that could benefit from Go's performance or concurrency, distributing Go binaries via PyPI with `go-to-wheel` offers a streamlined integration path. This allows end-users to install and run your Go-powered tools using familiar Python package managers like `pip` or `uv`, abstracting away the underlying Go dependency. Consider this pattern for new projects requiring high-performance components or cross-platform binary distribution without complex setup.
Key insights
Distributing Go binaries through PyPI simplifies installation and enables their use as Python package dependencies.
Principles
- PyPI can serve as a cross-platform distribution channel for compiled binaries.
- Python's packaging system handles architecture-specific binary selection.
Method
Use `go-to-wheel` to generate platform-specific Python wheels for Go binaries, then upload these wheels to PyPI using `twine upload`. A Python wrapper in the wheel executes the bundled binary.
In practice
- Use `uvx package-name` for quick execution of Go binaries from PyPI.
- Integrate Go CLIs into Python projects via `subprocess.run()` calls.
- Automate Go binary wheel creation with `go-to-wheel`.
Topics
- Go Binary Distribution
- PyPI Packaging
- Python Wheel
- go-to-wheel
- Cross-platform Deployment
Code references
Best for: Software Engineer, DevOps Engineer, Data Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Simon Willison's Weblog.