Skip to main content

Format embedded sql (squeel) in python source code files

Project description

Squeel

Format embedded sql (squeel) in python source code files.

Uses treesitter to query python strings inside the python files starting with a sql comment -- sql. Then formats the sql matching strings with the selected formatter, by default pg_format, and writes them back to the files.

Uses one of sqlparse or pg_format to format the SQL within the python code.

Warning

This is an experimental tool.

Its purpose is to change files on your system. I recommend checking your changes into git before running this tool in case it explodes. Ensure you give it the appropriate root_folder and glob patterns so it doesn't change files on your system that you don't want changed. No changes will be written to any files unless you supply the --change flag. The default behaviou is to dry run.

$ squeel .      
-- DRY RUN -- No actual changes will be made.
Found 42 files matching the glob pattern.
Would format 1 files:
test/data/test-1.py: 1 sql strings to be changed, 0 unchanged.

Requirements

pgFormatter if using the default format strategy pg_format

Install

pip install squeel

Usage

See squeel -h

squeel -h
usage: squeel [-h] [--change] [--glob GLOB] [--format_strategy FORMAT_STRATEGY] root_folder

Squeel

positional arguments:
  root_folder           The root folder to look for files to format

options:
  -h, --help            show this help message and exit
  --change              Dry run
  --glob GLOB           Glob pattern
  --format_strategy FORMAT_STRATEGY
                        Format strategy, one of 'pg_format' or 'sqlparse' (default pg_format)

Example run:

squeel --glob *.py --format_strategy sqlparse --change src

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

squeel-1.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

squeel-1.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file squeel-1.1.0.tar.gz.

File metadata

  • Download URL: squeel-1.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.11.0

File hashes

Hashes for squeel-1.1.0.tar.gz
Algorithm Hash digest
SHA256 67ee208a0d45b8f7a7363d7ea5e1ef0e5a7222306cd5b11ea2bedfd9a452ffc0
MD5 4f98af332df974bb9281f98128a5aabe
BLAKE2b-256 735278791ddcb4a0001d6c6e67aa80bf42dc79d1c477a4d419a404a75dbda769

See more details on using hashes here.

File details

Details for the file squeel-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: squeel-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.11.0

File hashes

Hashes for squeel-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8beff558fea02749446c6b6996464b99a4a06cdb1c5cb38c71c5b096e423246c
MD5 3fe4901eda32ae21a289c252c6116815
BLAKE2b-256 ac9ba3405e0d08c6abb63ce4488596c85f57754ae433e8659db9b5e3a2fff0b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page