--- id: pglast version: "8.4" license: GPL-3.0-or-later license_treatment: copyleft maintenance: active --- # pglast — PostgreSQL Languages AST and statements prettifier License: copyleft · Maintenance: active · Downloads: 4.8M/mo ## 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 above — 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 pip install pglast uv add pglast poetry add pglast ## Installing 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: unspecified - Install friction: medium - Maintenance: active - Downloads: 4.8M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags postgresql sql parser, parse sql statements, sql ast tree, postgresql query analysis, sql prettifier, postgres statement parser, sql syntax tree, sql-parsing, postgres-tools, ast-analysis [View on SkillFed](https://skillfed.io/packages/pglast) · [View on PyPI](https://pypi.org/project/pglast/)