Skip to main content

haltsql (Python)

Python client for HaltSQL, the policy firewall for LLM-generated PostgreSQL.

pip install haltsql            # httpx (+ the bundled engine on Linux x86_64/aarch64 and macOS arm64)
pip install 'haltsql[psycopg]' # + guarded execution on psycopg 3
pip install 'haltsql[asyncpg]' # + guarded execution on asyncpg
import psycopg
from haltsql import HaltSQLClient, QueryDenied, guard

hs = HaltSQLClient.from_env()  # HALTSQL_URL, HALTSQL_TOKEN, HALTSQL_TIMEOUT, HALTSQL_CA_FILE, ...

with psycopg.connect(DSN) as conn:
    try:
        result = guard.execute(conn, model_sql, {"tenant_id": session.tenant_id},
                               verifier=hs, statement_timeout_ms=5000, max_rows=500)
        print(result.columns, result.rows)
    except QueryDenied as denied:
        feedback = [(r.code, r.hint) for r in denied.verdict.reasons]  # give to the model
  • HaltSQLClient / AsyncHaltSQLClient: the sidecar HTTP API, with default timeouts (2 s per attempt), bounded retries, TLS verification on by default (private CA via verify=, mutual TLS via cert=), and a response size cap. Fail closed: any error raises; nothing is ever treated as allowed. The token never appears in repr() or error messages.
  • Verdict, Reason, BindParam: typed verdicts; verdict.bind_args() returns positional parameters for $1..$n.
  • guard.execute / guard.execute_async: verify, then run exactly the verified string with the bound parameters (psycopg 3, asyncpg, SQLAlchemy + psycopg 3).
  • NativeVerifier / AsyncNativeVerifier: verify in-process with the engine bundled in platform wheels (manylinux_2_28 x86_64/aarch64, macOS arm64), with no sidecar: NativeVerifier("policy.yaml").verify(sql, ctx), ~0.1 ms per call. Backends library (ctypes) or process (one long-lived CLI child); env HALTSQL_LIB, HALTSQL_BIN, HALTSQL_NATIVE=0|library. Create it after fork() (e.g. gunicorn post_fork).
  • LocalVerifier: verify with the haltsql CLI (bundled, $HALTSQL_BIN or PATH), one process per call.
  • haltsql.testing: FakeSidecar, FakeVerifier, make_verdict for your tests.

Full guide: docs/sdk-python.md.

Development

python3 -m venv .venv && .venv/bin/pip install -e '.[psycopg,asyncpg,test]'
.venv/bin/pytest -q

Tests that need the real binaries (_build/default/bin/..., or HALTSQL_BIN / HALTSQL_SERVER_BIN) or the lab Postgres (make -C lab up) are marked integration and skip when those are missing. native tests need _build/default/native/libhaltsql.so (or HALTSQL_LIB); set HALTSQL_REQUIRE_NATIVE=1 to fail instead of skip.

Platform wheel (bundles libhaltsql and the CLI; output in dist/):

scripts/build_wheel.sh            # dune release build, strip, tag, delocate/auditwheel
scripts/build_wheel.sh --pure     # py3-none-any wheel without the engine
HALTSQL_WHEEL=$(ls dist/*.whl) .venv/bin/pytest -q -m wheel   # install + smoke-test it

Metadata

Release files for haltsql 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for haltsql 0.0.1
File Size Uploaded Provenance Actions
haltsql-0.0.1.tar.gz 59.5 kB With provenance Details for haltsql-0.0.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for haltsql 0.0.1
File Actions
haltsql-0.0.1-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for haltsql-0.0.1-py3-none-manylinux_2_28_x86_64.whl
haltsql-0.0.1-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for haltsql-0.0.1-py3-none-manylinux_2_28_aarch64.whl
haltsql-0.0.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for haltsql-0.0.1-py3-none-macosx_11_0_arm64.whl
haltsql-0.0.1-py3-none-any.whl Python 3 none any Details for haltsql-0.0.1-py3-none-any.whl

Total release size: 21.4 MB

Release files / haltsql-0.0.1.tar.gz

Download URL haltsql-0.0.1.tar.gz
Size 59.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f5c3115dabbc4057dd007ddc93616d6666ab25e941e85a54796a3efb2410fc87
BLAKE2b-256 checksum
How to use checksums
7d68f296425182a3613f5e4662f25c50adc4fc1a8be5edbaba96da34c57969c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / haltsql-0.0.1-py3-none-manylinux_2_28_x86_64.whl

Download URL haltsql-0.0.1-py3-none-manylinux_2_28_x86_64.whl
Size 6.7 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
a2fa2d71139b22bd610cb0d75c05cc1d4e4c82eabf0d1065464be5ff33a6226d
BLAKE2b-256 checksum
How to use checksums
565b5179bbd9343294a1d98938afb5091b91acb39499098265beeffd6332fe08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / haltsql-0.0.1-py3-none-manylinux_2_28_aarch64.whl

Download URL haltsql-0.0.1-py3-none-manylinux_2_28_aarch64.whl
Size 7.3 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
ed1e3a13acd3bfc549d676db176bf009d18b405b44ae0624f0d3fa8cc725218a
BLAKE2b-256 checksum
How to use checksums
06f1f275cbd10c39e87005dbb5fea4c788329fa2d17be8f72bed13c90430ab0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / haltsql-0.0.1-py3-none-macosx_11_0_arm64.whl

Download URL haltsql-0.0.1-py3-none-macosx_11_0_arm64.whl
Size 7.3 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c0879b818f225a062a08e7eefd830aa2f14207a1f8e586fcd9271b796c60950a
BLAKE2b-256 checksum
How to use checksums
6d48b433fcc9570f7db8fcbf07acb79157d572591f70a332da9714fa851a5d67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / haltsql-0.0.1-py3-none-any.whl

Download URL haltsql-0.0.1-py3-none-any.whl
Size 44.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
277c36251b7c3f4979b9cc132215f44f68723ae2efba3d188ad83bdb92a77b8e
BLAKE2b-256 checksum
How to use checksums
af5045f750ec58508a5239cdf79701c60a14adb753a9e635c99ff25b9012cb7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for haltsql 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for haltsql-0.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page