Pretty format your SQL queries for easier reading.
Project description
Use this Pygments plugin alongside your usual SQL lexer and any output formatter to have your SQL queries reformatted for improved readability.
This filter modifies the stream of tokens that Pygments produces by inserting whitespace at key points to make the structure of the query more obvious.
Usage
For programmatic usage, add the filter to your lexer before highlighting:
from pygments import highlight, lexers, formatters from pygments_pprint_sql import SqlFilter lexer = lexers.MySqlLexer() lexer.add_filter(SqlFilter()) print highlight(text, lexer, formatters.TerminalFormatter())
This plugin is also compatible with the pygmentize CLI tool, via the -F option:
pygmentize -F pprint-sql script.sql
Notes
DDL statements like CREATE and ALTER are left unformatted because formatting them reliably would be a significant undertaking, especially for all flavours of SQL.
I’ve done my testing with queries from an application I work on that uses MySQL. In general it should transfer nicely to other RDBMS but I can make no guarantees.
Patches always welcome, provided they come with test cases!
Alternatives
SQLParse is a standalone parser and formatter package with some nice options for customizing how formatting occurs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for pygments-pprint-sql-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 741dc47408ea7b1279b3272f4deb10074ea952a94418b6490f20ed187beba498 |
|
MD5 | 91409e6db333c15c6ac72fcedb4d2b2e |
|
BLAKE2b-256 | 757a38b17da0718d6cd0e6e4fa02f758d663c73a045c489f690e937b94f80dda |