pglast
PostgreSQL Languages AST and statements prettifier
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
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 · maintenance · safety
GPL-3.0-or-later (copyleft) — 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.
last release 2026-07-22 (23 days) · last repo commit 2026-08-13 · 402 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 4,822,899 downloads/mo, #2,220 on PyPI
Alternatives
Verify before relying
pip install pglast
import pglast
ast = pglast.parse('SELECT * FROM table')
print(pglast.prettify(ast))- 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
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 on it.
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
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 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: SQLTopic :: DatabaseTopic :: Utilities |
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
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “postgresql sql parser”
- pglastParses PostgreSQL SQL statements into an abstract syntax tree and…
- ddlparseParses CREATE TABLE DDL statements from MySQL, MariaDB, PostgreSQL,…
- pgsanityPgSanity validates PostgreSQL SQL syntax by wrapping the ecpg parser,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Utilities packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Detects and normalizes text encoding from unknown or ambiguous sources, supporting all IANA character sets that Python's core library provides codecs for, with the ability to register custom codecs.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Pygments is a syntax highlighter that colorizes source code and text in over 500 languages and formats, outputting to HTML, LaTeX, RTF, SVG, images, or ANSI terminal sequences.
Install it if you need to display or transform source code.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
See also fparser · sqlparse · pgsanity · collate-sqllineage · fugue-sql-antlr · sqloxide · sqlglot · sqllineage · schemainspect · tree-sitter-sql