Skip to main content

a tool that lints/fixes SQL code within Python strings using SQLFluff

Project description

PyLintSQL

A tool that lints/fixes SQL code within Python strings using SQLFluff.

Installation

# Install from PyPI
pip install pylintsql

Usage

Lint SQL in Python files in the current directory

pylintsql lint

Fix SQL in Python files in a specific directory

pylintsql fix path/to/directory

Use a custom configuration file

pylintsql lint --config /path/to/config

SQL String Identification

PyLintSQL identifies SQL strings by looking for the --sql marker at the beginning of the string. Only strings with this marker will be processed:

# This SQL string will be linted
sql = """--sql
    SELECT
      user_id,
      COUNT(*) as order_count
    FROM orders
    WHERE created_at > '2023-01-01'
    GROUP BY user_id
"""

# This regular string will be ignored
other_text = """
    This is not SQL and won't be processed
"""

Configuration

PyLintSQL uses pyproject.toml for configuration, which is also a configuration file for SQLFluff itself. This means you can:

  • Use all standard SQLFluff configuration options under [tool.sqlfluff.*] sections
  • Define pylintsql-specific settings under [tool.pylintsql]

Example configuration:

# SQLFluff configuration
[tool.sqlfluff.core]
dialect = "bigquery"  # Or your preferred dialect
max_line_length = 99
exclude_rules = ["RF01", "RF02", "RF04", "ST06"]

[tool.sqlfluff.indentation]
tab_space_size = 2
indented_joins = false
indented_ctes = false

# PyLintSQL specific configuration
[tool.pylintsql]
exclude = [ # Directories/files to exclude
    ".venv/**",  
    "build/**",
    "dist/**",
    "tests/**"
]

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pylintsql-0.0.9-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file pylintsql-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: pylintsql-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pylintsql-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a87e1bf5d1f194814171fa072941c384414413a183c402e5e2524ff8f3b7ab0c
MD5 6e7efffc6d315b6328a85e893d6e28c1
BLAKE2b-256 f236a45def2b9c0c6c520c35a9e41ff6239f792852aefff6b5be77b1214faf6e

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