pgparse
Python bindings for libpg_query, exposing PostgreSQL's internal parser to Python. Parse, normalize, and fingerprint SQL statements using the same parser that PostgreSQL itself uses.
PostgreSQL Compatibility
| pgparse | libpg_query | PostgreSQL |
|---|---|---|
| 1.x | 17-latest | 17 |
Installation
pip install pgparse
Wheels are provided for Linux (manylinux and musllinux, x86_64 and aarch64) and macOS (arm64) for Python 3.11+ via the stable ABI (abi3). Installing from source requires gcc, make, and the libpg_query build dependencies.
Usage
Parse
Returns the internal PostgreSQL parse tree as a list of statement dicts:
import pgparse
result = pgparse.parse("SELECT * FROM orders WHERE id = 1")
# [{'stmt': {'SelectStmt': {...}}}]
Normalize
Replaces literal values with positional placeholders — useful for query grouping and log analysis:
pgparse.normalize("SELECT * FROM orders WHERE id = 1")
# "SELECT * FROM orders WHERE id = $1"
pgparse.normalize("SELECT * FROM orders WHERE id = 2")
# "SELECT * FROM orders WHERE id = $1"
Fingerprint
Produces a stable hash that is identical for structurally equivalent queries regardless of literal values or formatting:
pgparse.fingerprint("SELECT * FROM orders WHERE id = 1")
# "0357e3db3ead2de761ea5c0f064bfddc0048cad5eb"
pgparse.fingerprint("SELECT * FROM orders WHERE id = 99")
# "0357e3db3ead2de761ea5c0f064bfddc0048cad5eb" # same fingerprint
Parse PL/pgSQL
Parse a PL/pgSQL function body:
func = """
CREATE FUNCTION sales_tax(subtotal real) RETURNS real AS $$
BEGIN
RETURN subtotal * 0.06;
END;
$$ LANGUAGE plpgsql;
"""
result = pgparse.parse_pgsql(func)
Error Handling
Invalid SQL raises pgparse.PGQueryError with the error message and cursor position:
try:
pgparse.parse("SELECT FROM WHERE")
except pgparse.PGQueryError as e:
print(e.message) # syntax error at or near "WHERE"
print(e.position) # 13
Documentation
Full API reference and examples: gmr.github.io/pgparse
Release files for pgparse 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pgparse-1.0.3.tar.gz | 3.0 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pgparse-1.0.3-cp311-abi3-musllinux_1_2_x86_64.whl | CPython 3.11 | abi3 | Linux musl 1.2+ x86-64 | Details |
| pgparse-1.0.3-cp311-abi3-musllinux_1_2_aarch64.whl | CPython 3.11 | abi3 | Linux musl 1.2+ ARM64 | Details |
| pgparse-1.0.3-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| pgparse-1.0.3-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 | Details |
| pgparse-1.0.3-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 15.8 MB
Release files / pgparse-1.0.3.tar.gz
| Download URL | pgparse-1.0.3.tar.gz |
|---|---|
| Size | 3.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f5e15f14d459d90cf38a4e594079db206f8e8c2dab8153f3700e9333d068af0
|
|
BLAKE2b-256 checksum How to use checksums |
e1bfc90517b33ff69b1e0f534ae0c143598d582ad3a53c4d501a54e958ebaf88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 19, 2026.
Transparency logRelease files / pgparse-1.0.3-cp311-abi3-musllinux_1_2_x86_64.whl
| Download URL | pgparse-1.0.3-cp311-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
de8a3584bbc82abcb7b833ed6aa6575bc746cede82b6c8f8294dafb115e8c566
|
|
BLAKE2b-256 checksum How to use checksums |
cd6b7a5d9209cbf519655a662ec40b03d1ebcded5cb2637fe08a9b4cfa3343bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 19, 2026.
Transparency logRelease files / pgparse-1.0.3-cp311-abi3-musllinux_1_2_aarch64.whl
| Download URL | pgparse-1.0.3-cp311-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.11 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b6f009abca3dc9c5a5a0f0fdf1e00c81bd5a2f6c6f51e0c80d944bb93fbef4ba
|
|
BLAKE2b-256 checksum How to use checksums |
b8de48db5269759c7c441bf4fb550b6a9d965e76940b9633aa7e3b2b87d42f52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 19, 2026.
Transparency logRelease files / pgparse-1.0.3-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pgparse-1.0.3-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f5d24c7a6192546888b75a879e9b0aad32f6e723fd50c1d5b75811e8f87e75f3
|
|
BLAKE2b-256 checksum How to use checksums |
626d48127deabf2c3af38959a03f6e17363db173c870af10c00f57d84fe01a58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 19, 2026.
Transparency logRelease files / pgparse-1.0.3-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | pgparse-1.0.3-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d039a78754bbba535713365744326ff18529ef6742db1d059d451bd6f452265d
|
|
BLAKE2b-256 checksum How to use checksums |
dee2efaba57614172682398f26ec6731e0a6d3ae836dac070f900b053e6592b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 19, 2026.
Transparency logRelease files / pgparse-1.0.3-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | pgparse-1.0.3-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 690.9 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1227fccd54cf2d09e889e747fef408a3dff91799dd572a930bea101236e5fa3c
|
|
BLAKE2b-256 checksum How to use checksums |
b72ebf2f163ff5d2a0380483796974719200df1d9e9da6da03a84ecc0842038b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 19, 2026.
Transparency log