SQL Complexity Estimator
This package provides a simple algorithm to calculate complexity of SQL expressions.
It's based on SQLGlot abstract syntax tree, so the provided SQL must be compatible with SQLGlot engines.
The rules are the following:
- +1 per join expression
- +1 per predicate after WHERE or HAVING
- +1 per CTE
- +1 per GROUP BY expression
- +1 per UNION or INTERSECT
- +1 per function call
- +1 per CASE expression
This package is inspired on the comments of this stack overflow thread.
Install
python -m pip install sql-complexity
poetry add sql-complexity
uv add sql-complexity
Run with uvx
uvx --refresh sql-complexity
Run from the CLI
sql-complexity some.sql
cat myfile.sql | sql-complexity
Using it in your code
from sql_complexity import SQLComplexityAssessment
assessor = SQLComplexityAssessment()
score = assessor.assess(contents)
print(score)
print(score.total)
Metadata
Release files for sql-complexity 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sql_complexity-0.1.6.tar.gz | 4.7 kB | Without provenance | Details for sql_complexity-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sql_complexity-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for sql_complexity-0.1.6-py3-none-any.whl |
Total release size: 11.1 kB
Release files / sql_complexity-0.1.6.tar.gz
| Download URL | sql_complexity-0.1.6.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc028a3d3561b53099d593f1e63eb4a48e3e8acfeed6d45d16564d16ebbc6868
|
|
BLAKE2b-256 checksum How to use checksums |
3ed47dd0572c190ae5d640dde2a39829d92afdf21d49f05dbcfdb6e713cba617
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Release files / sql_complexity-0.1.6-py3-none-any.whl
| Download URL | sql_complexity-0.1.6-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
506f94e5f05c01f9c13228f9b449860e520a3f42145e8fe409721f4fd805f146
|
|
BLAKE2b-256 checksum How to use checksums |
143530cbd4ef7ab4b6d324fd8e74e9fcf7a9e0e78531a584e3d834937e8e3531
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Security for sql-complexity 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.