Skip to content

Flamefork/sqlc-py

Repository files navigation

sqlc-py

License main PyPI - Version

sqlc-py packages the sqlc CLI for Python. It provides the sqlc command-line tool as a pip-installable package, built from the official Go source and distributed as platform-specific wheels.

Installation

pip install sqlc

Usage

After installation, the sqlc command is available directly:

sqlc generate
sqlc vet
sqlc compile

From Python code, use get_binary_path() to locate the bundled binary:

import subprocess
from sqlc import get_binary_path

result = subprocess.run([get_binary_path(), "generate"], check=True)

See the sqlc documentation for full usage details.

How it works

build_wheel.py compiles the Go binary and builds platform-specific wheels. CI builds wheels per-platform in a matrix, then publishes all wheels in a separate job.

Why per-platform builds with CGO?

Cross-compiling from a single CI host with CGO_ENABLED=0 would be simpler, but this project enables CGO_ENABLED=1 for most targets and runs the build natively per platform. Current exceptions are linux-*-musl and windows-arm64, which are built with CGO_ENABLED=0. The reason for preferring CGO where possible is that sqlc depends on wasilibs/go-pgquery — a library that, without CGO, falls back to wazero and doesn't cache compiled WASM binaries, adding ~500ms to every sqlc invocation.

Version Mapping

Package versions follow sqlc releases — e.g., package version 1.30.0 ships sqlc v1.30.0. Packaging-only fixes use PEP 440 post releases: 1.30.0.post1, 1.30.0.post2, etc.

About

sqlc binary packaged for Python

Resources

License

Stars

Watchers

Forks

Contributors