pglast
PostgreSQL Languages AST and statements prettifier
What it is and what it does
pglast is a Python module that wraps the PostgreSQL parser (via libpg_query) to expose SQL statements as an abstract syntax tree. It lets you programmatically inspect the structure of SQL queries—their clauses, expressions, and relationships—rather than treating them as opaque strings. The tree is built from interconnected nodes that mirror PostgreSQL's internal parse representation.
The package is typically used to analyze, validate, or transform SQL statements without executing them. Common tasks include extracting table and column references, detecting query patterns, reformatting SQL for readability, or building tools that need to understand query structure. It has no runtime dependencies and covers modern Python versions; installation requires compiled wheels for your platform.
Use it for:
- Extract table and column names from arbitrary SQL queries for dependency analysis or schema mapping
- Reformat or prettify SQL statements to a consistent style for code review or documentation
- Build linters or validators that check SQL queries for anti-patterns or compliance rules
- Analyze query structure to optimize or rewrite statements programmatically
- Generate documentation or diagrams of data lineage from SQL statement trees
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses PostgreSQL SQL statements into an abstract syntax tree and provides tools to inspect and prettify the parsed structure.
Yes, if you need to parse and inspect PostgreSQL SQL statements programmatically. The package is actively maintained, has no runtime dependencies, and covers modern Python versions. The GPL-3.0-or-later license is a blocker only if you cannot open-source derivative works; otherwise, it's a solid choice for SQL analysis tasks.
Install
pglast on PyPI
pip
pip install pglastuv
uv add pglastpoetry
poetry add pglastInstalling pglast
Before you install
Medium install friction due to compiled wheels for multiple platforms and Python versions (3.10–3.14). Active maintenance with recent release 23 days ago and 402 repository stars suggests stable, ongoing support.
License in practice
Licensed under GPL-3.0-or-later (copyleft). Use in proprietary software requires careful review of your licensing obligations, as derivative works must also be open-source under compatible terms.
Quickstart
pip install pglast
import pglast
ast = pglast.parse('SELECT * FROM table')
print(pglast.prettify(ast))
Verify before relying
- Minimum Python version requirement (classifiers list 3.10–3.14 but requires_python is unspecified)
- Whether the package works with all PostgreSQL versions or requires a specific server version
- Performance characteristics when parsing very large or complex SQL statements
Package facts
| License | GPL-3.0-or-later (copyleft) |
| Python support | not specified |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 23 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,822,899/month — #2,220 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pglast-8.4-cp310-cp310-macosx_10_9_x86_64.whl; pglast-8.4-cp310-cp310-macosx_11_0_arm64.whl; pglast-8.4-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; pglast-8.4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; pglast-8.4-cp310-cp310-musllinux_1_2_aarch64.whl; pglast-8.4-cp310-cp310-musllinux_1_2_x86_64.whl; pglast-8.4-cp310-cp310-win32.whl; pglast-8.4-cp310-cp310-win_amd64.whl; pglast-8.4-cp311-cp311-macosx_10_9_x86_64.whl; pglast-8.4-cp311-cp311-macosx_11_0_arm64.whl; pglast-8.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; pglast-8.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; pglast-8.4-cp311-cp311-musllinux_1_2_aarch64.whl; pglast-8.4-cp311-cp311-musllinux_1_2_x86_64.whl; pglast-8.4-cp311-cp311-win32.whl; pglast-8.4-cp311-cp311-win_amd64.whl; pglast-8.4-cp312-cp312-macosx_10_13_x86_64.whl; pglast-8.4-cp312-cp312-macosx_11_0_arm64.whl; pglast-8.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; pglast-8.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Keywords: postgresql, parser, sql, prettifier
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
fparserfparser parses Fortran source code (Fortran 77…
permissive · top 15,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
pgsanityPgSanity validates PostgreSQL SQL syntax by…
permissive · top 15,000 on PyPI
collate-sqllineageAnalyzes SQL statements to extract source and…
permissive · top 5,000 on PyPI
fugue-sql-antlrParses Fugue SQL dialect into an abstract…
permissive · top 5,000 on PyPI
sqloxidesqloxide parses SQL queries into a typed…
permissive · top 15,000 on PyPI
sqlglotSQLGlot parses, transpiles, optimizes, and…
permissive · top 1,000 on PyPI
sqllineageSQLLineage parses SQL statements to extract and…
permissive · top 5,000 on PyPI
schemainspectInspects PostgreSQL database schemas to extract…
permissive · top 15,000 on PyPI
tree-sitter-sqlProvides a tree-sitter SQL grammar for parsing…
permissive · top 5,000 on PyPI