postgast¶
BSD-licensed Python bindings to libpg_query, the PostgreSQL parser packaged as a standalone C library.
Parse, deparse, normalize, fingerprint, split, and scan PostgreSQL SQL
statements from Python. postgast declares one runtime dependency,
protobuf. The vendored C library ships inside the wheel.
import postgast
# Parse a query into an AST
tree = postgast.parse("SELECT id, name FROM users WHERE active = true")
# Deparse an AST back to SQL
sql = postgast.deparse(tree)
# Normalize a query (replace constants with placeholders)
postgast.normalize("SELECT * FROM users WHERE id = 42")
# => "SELECT * FROM users WHERE id = $1"
# Fingerprint a query
fp = postgast.fingerprint("SELECT * FROM users WHERE id = 42")
# Split a multi-statement string
postgast.split("SELECT 1; SELECT 2;")
# => ["SELECT 1", "SELECT 2"]
Installation¶
pip install postgast
LLM-Friendly Docs¶
postgast publishes machine-readable documentation for AI coding
assistants:
llms.txt holds a short overview.
llms-full.txt holds the complete documentation in one file.
These files follow the llms.txt standard.