Skip to main content

pg-query-python

Python bindings for libpg_query — parse, deparse, and walk PostgreSQL SQL statements.

Ships pre-built wheels with the libpg_query shared library for Linux (x86_64, aarch64) and macOS (x86_64, arm64). No compiler required at install time.

Install

pip install pg-query-python

Usage

Parse SQL to a protobuf AST

from pg_query import parse

tree = parse("SELECT id, name FROM users WHERE active = true")
print(tree)

Deparse an AST back to SQL

from pg_query import parse, deparse

tree = parse("SELECT 1")
sql = deparse(tree)
assert sql == "SELECT 1"

Walk the AST

from pg_query import parse, walk

tree = parse("SELECT id FROM users JOIN orders ON users.id = orders.user_id")
for field_name, node in walk(tree):
    if type(node).DESCRIPTOR.name == "RangeVar":
        print(f"Table: {node.relname}")

Visitor pattern

from pg_query import parse, Visitor

class TableFinder(Visitor):
    def __init__(self):
        self.tables = []

    def visit_RangeVar(self, node):
        self.tables.append(node.relname)

tree = parse("SELECT * FROM users, orders")
finder = TableFinder()
finder.visit(tree)
print(finder.tables)  # ['users', 'orders']

Building from source

If no pre-built wheel is available for your platform, pip will build from source. You'll need git, make, and a C compiler:

pip install pg-query-python --no-binary pg-query-python

To target a specific libpg_query version:

LIBPG_QUERY_TAG=16-latest pip install pg-query-python --no-binary pg-query-python

License

BSD-3-Clause (this package) and BSD-3-Clause + PostgreSQL License (libpg_query).

Metadata

Release files for pg-query-python 0.1.3

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

Source distribution (sdist)

Source distribution for pg-query-python 0.1.3
File Size Uploaded Provenance Actions
pg_query_python-0.1.3.tar.gz 88.2 kB With provenance Details for pg_query_python-0.1.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pg-query-python 0.1.3
File Actions
pg_query_python-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for pg_query_python-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pg_query_python-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details for pg_query_python-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
pg_query_python-0.1.3-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for pg_query_python-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
pg_query_python-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for pg_query_python-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pg_query_python-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ ARM64 Details for pg_query_python-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
pg_query_python-0.1.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for pg_query_python-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
pg_query_python-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for pg_query_python-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pg_query_python-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ ARM64 Details for pg_query_python-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
pg_query_python-0.1.3-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for pg_query_python-0.1.3-cp311-cp311-macosx_11_0_arm64.whl

Total release size: 21.9 MB

Release files / pg_query_python-0.1.3.tar.gz

Download URL pg_query_python-0.1.3.tar.gz
Size 88.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6c540159954e20208a0be1a00d992d23d71d64aca5d65a215f814b6191ab3a54
BLAKE2b-256 checksum
How to use checksums
5d0533c37ed4162fc4150e221e83c1d063ae6102fba4c0c291551da0b1286ffa
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pg_query_python-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
204ed67cd9582b091601ee2f874261f406b0838c2032edb1a1955ee0bce1824c
BLAKE2b-256 checksum
How to use checksums
8ed44a18cd436369d446298abbeb6af52783dfb4511465a8197e0fb93ac978de
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pg_query_python-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.2 MB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
23b6b6c89d2ab9416d9c14ba3a1934d1481e0ed6f20df41543b5e68f75b4d586
BLAKE2b-256 checksum
How to use checksums
6ef870b7a6712efb2d32105792a13381651df6f74e7bb36dce38c6330f0ed734
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp313-cp313-macosx_11_0_arm64.whl

Download URL pg_query_python-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Size 779.7 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0b25270edf2911cea6c2970dbd518cd927d82012334cf8931b08642d1fecbc05
BLAKE2b-256 checksum
How to use checksums
4eebf8fddf81ccc77dd63dcf8a9063dc13d10fa35e9cbe1b8ac620df52ef6fd1
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pg_query_python-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a6499508c3fc86770d01d25f33453813a7030b856d7194fde58f762d04bc9ac3
BLAKE2b-256 checksum
How to use checksums
ae953d28099ea6b0648626bfe5ff8cff990e8ac83c60cf10e5a22ba4cd0c7cfc
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pg_query_python-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.2 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
36356df6cfbf199d31cfc46a055fac96c81ed3139ad6f4f1cb7cbd31c45613f2
BLAKE2b-256 checksum
How to use checksums
02ed7316d9c670abd99fe98f8c16cbe0fa93995f6eb0a2303c62ce9c06165303
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL pg_query_python-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Size 779.7 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d16e46d328b1829537eb86ea54a138e2b2651a938f397390899b9eae62b5058b
BLAKE2b-256 checksum
How to use checksums
5459d4986f2ed323b1c1b83b3602b6178963812f1714bee418239847e45ca8e2
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pg_query_python-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
84f376ed80f5500cc423ffc5a4009175ad7de59dbd6eb64d77da7c981a694bb0
BLAKE2b-256 checksum
How to use checksums
a4502977c1067e5dc7e290db119239bdc4a618c7282ec1107b9b6aa9050c6177
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pg_query_python-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.2 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
6f9243d2c1fdc70b2e67d09530cda7db840b95c656c81798287ab1269e555745
BLAKE2b-256 checksum
How to use checksums
8a6152805763218b05d889426a9d6fb791eba2c978a105d13f7caf26c462e46b
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 25, 2026.

Transparency log

Release files / pg_query_python-0.1.3-cp311-cp311-macosx_11_0_arm64.whl

Download URL pg_query_python-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Size 779.7 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9dc4511ae6004408677bf81456343cf4f7db283d00b7ae6c3134913753622045
BLAKE2b-256 checksum
How to use checksums
bdb167d7773871ddbeb69790a2e678022c1157da2adce276bc54b8b084bd9498
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 25, 2026.

Transparency log

Security for pg-query-python 0.1.3

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 10 files in this release have been uploaded with provenance metadata.

Select from 10 files

Attestation for pg_query_python-0.1.3.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 Mar 25, 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.1.3 This release

10 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