Skip to main content

PySquel

POC for linting SQL statements in Python.

Relying on sqlfluff.

The name is inspired by Czech word paskvil which means messed up.

Concept

Using str subclass called sql to mark all SQL statements for linting. It causes avoidance of parsing the SQL statements from all strings.

from pysquel import sql

my_sql = sql("SELECT * FROM table")

# `sql` is a just subclass of the str
>>> type(my_sql)
<class 'str'>

>>> sql("SELECT * FROM {table}").format(table="super_table")
'SELECT * FROM super_table'

It could be better in the future:

  • tagstr
    sql"SELECT FROM table"
    
    sql_f"SELECT FROM {table}"
    
  • dedent
    sql_d"""
      SELECT 
      FROM table
    """
    
    sql_df"""
      SELECT 
      FROM {table}
    """
    

Usage

# tests/test_lint.py

from pysquel import sql

bad_sql = sql(
    """
  SELECT * 
FROM 
          table
""")

Run pysquel . to lint all sql statements in the current directory:

tests/test_lint.py :
--------------------------------------------------------------------------------
  SELECT * 
FROM 
          table

--------------------------------------------------------------------------------
{'line_no': 1, 'line_pos': 1, 'code': 'LT01', 'description': "Expected only single space before 'SELECT' keyword. Found '  '.", 'name': 'layout.spacing'}
{'line_no': 1, 'line_pos': 1, 'code': 'LT02', 'description': 'First line should not be indented.', 'name': 'layout.indent'}
{'line_no': 1, 'line_pos': 1, 'code': 'LT13', 'description': 'Files must not begin with newlines or whitespace.', 'name': 'layout.start_of_file'}
{'line_no': 1, 'line_pos': 3, 'code': 'AM04', 'description': 'Query produces an unknown number of result columns.', 'name': 'ambiguous.column_count'}
{'line_no': 1, 'line_pos': 11, 'code': 'LT01', 'description': 'Unnecessary trailing whitespace.', 'name': 'layout.spacing'}
{'line_no': 2, 'line_pos': 5, 'code': 'LT01', 'description': 'Unnecessary trailing whitespace.', 'name': 'layout.spacing'}
{'line_no': 3, 'line_pos': 1, 'code': 'LT02', 'description': 'Expected indent of 4 spaces.', 'name': 'layout.indent'}
================================================================================

TODO

  • config
  • exclude rules
  • exclude dirs
  • noqa
  • sqlfluff config (dialect, templating, ...)
  • custom token instead of sql?
  • lint missing sql prefix for potential SQL statements

Release files for pysquel 0.0.1

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

Source distribution (sdist)

Source distribution for pysquel 0.0.1
File Size Uploaded
pysquel-0.0.1.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysquel 0.0.1
File Interpreter ABI Platform
pysquel-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 kB

Release files / pysquel-0.0.1.tar.gz

Download URL pysquel-0.0.1.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
86e00cb5f5fca51a4e5b39127fb8d690792297787565dd5e5ab3a93c65508289
BLAKE2b-256 checksum
How to use checksums
53348a2a1a84e7f6c124e8adb4a1fb7a2585fd53629f703f8cdaea03c11312ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.11.6 Linux/6.5.0-10-generic

Release files / pysquel-0.0.1-py3-none-any.whl

Download URL pysquel-0.0.1-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0154811770f18617b118865abd5bf6be4693e2d85a7c62ce27512b08249d8c81
BLAKE2b-256 checksum
How to use checksums
8b98b9302210834ad89bd09a6c7702470a14e9e8a85dd356ff84e0d86dff1178
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.11.6 Linux/6.5.0-10-generic

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

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