philiprehberger-sql-print
Pretty-print and format SQL queries for debugging.
Installation
pip install philiprehberger-sql-print
Usage
Format SQL
from philiprehberger_sql_print import format_sql
query = "SELECT id, name FROM users WHERE active = 1 AND role = 'admin' ORDER BY name"
print(format_sql(query))
Output:
SELECT id, name
FROM users
WHERE active = 1
AND role = 'admin'
ORDER BY name
Print SQL with syntax highlighting
from philiprehberger_sql_print import print_sql
print_sql("SELECT * FROM orders LEFT JOIN users ON orders.user_id = users.id WHERE total > 100")
Prints formatted SQL with ANSI color-coded keywords, strings, and numbers.
Disable colors or uppercase
from philiprehberger_sql_print import print_sql
# No ANSI colors (useful for logging)
print_sql("select id from users", color=False)
# Preserve original keyword casing
print_sql("select id from users", uppercase=False)
Custom indentation
from philiprehberger_sql_print import format_sql
print(format_sql("SELECT id FROM users WHERE active = 1", indent=4))
API
| Function | Description |
|---|---|
format_sql(sql, *, indent=2, uppercase=True) -> str |
Format a SQL query with newlines and indentation. |
print_sql(sql, *, indent=2, uppercase=True, color=True, file=None) -> None |
Print a formatted SQL query with optional ANSI syntax highlighting. |
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
sql |
str |
— | The SQL query string to format. |
indent |
int |
2 |
Number of spaces for indentation. |
uppercase |
bool |
True |
Whether to uppercase SQL keywords. |
color |
bool |
True |
Whether to apply ANSI color codes (print_sql only). |
file |
TextIO | None |
None |
Output stream. Defaults to sys.stdout (print_sql only). |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Release files for philiprehberger-sql-print 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| philiprehberger_sql_print-0.1.7.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| philiprehberger_sql_print-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.3 kB
Release files / philiprehberger_sql_print-0.1.7.tar.gz
| Download URL | philiprehberger_sql_print-0.1.7.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bca90c68c88064aaa6da5abe91d55d1454ff142ec65ad1746007d93cba408d75
|
|
BLAKE2b-256 checksum How to use checksums |
ae51bfdab41d428ffcbb8581a4f155f0a83c0c601a86fde52e79efaafa495cfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_sql_print-0.1.7-py3-none-any.whl
| Download URL | philiprehberger_sql_print-0.1.7-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a287bfdf34b4d9bf9f81993848db458ea034d76fbe049c655baa42a9bb1b860d
|
|
BLAKE2b-256 checksum How to use checksums |
3e003d60acd464eb154512192d9009755e5e2c0238f47cc4bb2bce88fd5c8124
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|