Skip to main content
https://travis-ci.org/paetzke/format-sql.svg?branch=master https://coveralls.io/repos/paetzke/format-sql/badge.svg?branch=master https://badge.fury.io/py/format-sql.svg https://readthedocs.org/projects/format-sql/badge/?version=latest

Makes your SQL readable.

https://paetzke.me/static/images/format-sql.gif

An example:

    sql = """ SELECT country, product, SUM(profit) FROM
sales   left join x on x.id=sales.k GROUP BY country,
product having f > 7 and fk=9 limit 5;    """

Will result in:

sql = """
    SELECT
        country,
        product,
        SUM(profit)
    FROM
        sales
        LEFT JOIN x ON
            x.id = sales.k
    GROUP BY
        country,
        product
    HAVING
        f > 7
        AND fk = 9
    LIMIT 5; """

Install format-sql via pip:

$ pip install format-sql

You can then just call format-sql with files and directories:

$ format-sql -h
usage: format-sql [-h] [--types TYPES] [-r] [--no-semicolon] [--version]
                  [--debug] [--dry-run]
                  paths [paths ...]

positional arguments:
  paths

optional arguments:
  -h, --help       show this help message and exit
  --types TYPES    Only process these given file types.
  -r, --recursive  Process files found in subdirectories.
  --no-semicolon   Try to detect SQL queries with no trailing semicolon.
  --version        show program's version number and exit
  --debug          Print available debug information.
  --dry-run        Print the altered output and do not change the file.

For example:

$ format-sql my-file.py

Or recursively with directory:

$ format-sql -r my-directory/

You can try format-sql online: http://format-sql.de.

Metadata

Release files for format-sql 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for format-sql 0.12.0
File Size Uploaded
format-sql-0.12.0.tar.gz 12.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for format-sql 0.12.0
File Interpreter ABI Platform
format_sql-0.12.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 27.2 kB

Release files / format-sql-0.12.0.tar.gz

Download URL format-sql-0.12.0.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ad968b406402351e04d78cb46947ae783dcda479461913ea4d5a5c4f2ee2d3c2
BLAKE2b-256 checksum
How to use checksums
daefc2e47d839377d3f16efdfd56ba417e86c352a876a6b254c56f5177c4dd08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / format_sql-0.12.0-py2.py3-none-any.whl

Download URL format_sql-0.12.0-py2.py3-none-any.whl
Size 14.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d6bd6817d02ad3e9b7ec001a205aa2f6fbab2a44585d2e6a978460898bdd7286
BLAKE2b-256 checksum
How to use checksums
3007ff409992ea5a36238fbf678d62fe12f93bca5ea1a550287deb1c4d7d38ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page