pgfmt
A PostgreSQL SQL formatter with multiple style options.
pgfmt parses SQL using pgparse (PostgreSQL's own parser via libpg_query) and reformats it according to one of several well-known style guides.
Installation
pip install pgfmt
CLI Usage
# Format a file (default: river style)
pgfmt query.sql
# Format from stdin
echo "SELECT a,b FROM t WHERE x=1" | pgfmt
# Choose a style
pgfmt --style mozilla query.sql
pgfmt --style dbt query.sql
# Check if already formatted (exit 1 if not)
pgfmt --check query.sql
Library Usage
import pgfmt
sql = "SELECT a, b FROM my_table WHERE x = 1 AND y = 2"
# Default (river) style
print(pgfmt.format(sql))
# Choose a style
print(pgfmt.format(sql, style='mozilla'))
print(pgfmt.format(sql, style='dbt'))
Styles
river (default)
Based on sqlstyle.guide by Simon Holywell. Keywords are right-aligned to form a visual "river" separating keywords from content. Uppercase keywords.
SELECT a.title,
a.release_date
FROM albums AS a
WHERE a.title = 'Charcoal Lane'
OR a.title = 'The New Danger';
mozilla
Based on the Mozilla SQL Style Guide. Keywords left-aligned at column 0, content indented 4 spaces underneath. One item per line. Uppercase keywords.
SELECT
a.title,
a.release_date
FROM albums AS a
WHERE
a.title = 'Charcoal Lane'
OR a.title = 'The New Danger';
aweber
Based on river style with JOINs as river keywords. INNER JOIN, LEFT JOIN, etc. participate in river alignment. Uppercase keywords.
SELECT r.last_name
FROM riders AS r
INNER JOIN bikes AS b
ON r.bike_vin_num = b.vin_num
AND b.engines > 2;
dbt
Based on dbt Labs' SQL style. Lowercase keywords, 4-space indent, blank lines between clauses, generous whitespace. Explicit join types.
select
a.title,
a.release_date
from albums as a
where
a.title = 'Charcoal Lane'
or a.title = 'The New Danger'
gitlab
Based on the GitLab SQL Style Guide. Uppercase keywords, 2-space indent, blank lines inside CTE bodies.
SELECT
a.title,
a.release_date
FROM albums AS a
WHERE
a.title = 'Charcoal Lane'
OR a.title = 'The New Danger';
kickstarter
Based on the Kickstarter SQL Style Guide. Uppercase keywords, 2-space indent, JOIN ON on same line, compact CTE chaining.
SELECT
a.title,
a.release_date
FROM albums AS a
INNER JOIN orders AS o ON a.id = o.album_id
WHERE
a.title = 'Charcoal Lane'
AND a.year > 2000;
mattmc3
Based on the Modern SQL Style Guide
by mattmc3. Lowercase river-style with leading commas. Uses plain join
instead of inner join.
select a.title
, a.release_date
from albums as a
join orders as o
on a.id = o.album_id
where a.title = 'Charcoal Lane'
and a.year > 2000;
Release files for pgfmt 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pgfmt-0.1.0.tar.gz | 1.2 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pgfmt-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / pgfmt-0.1.0.tar.gz
| Download URL | pgfmt-0.1.0.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
011f154a8612346da0985351deed2563bb3bbd16e62eb808b17058719a679d50
|
|
BLAKE2b-256 checksum How to use checksums |
faf8d562771b3b68513c2c6a5b3a21da867a40a7a518dff770e08eb42c96c4d9
|
| 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 27, 2026.
Transparency logRelease files / pgfmt-0.1.0-py3-none-any.whl
| Download URL | pgfmt-0.1.0-py3-none-any.whl |
|---|---|
| Size | 33.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1da1f3ad113148c97f05d75220954d4f34f7436c979ddef78621182f00ed1347
|
|
BLAKE2b-256 checksum How to use checksums |
1dd1abb7e717fbfdfaafddd8a88692b69ec3b2b6cd47798ca4e905a247618f41
|
| 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 27, 2026.
Transparency log