Metadata-Version: 2.3
Name: sql-complexity
Version: 0.1.6
Summary: A SQL complexity library and CLI
Author: Nahuel Defossé
Author-email: Nahuel Defossé <nahuel.deofsse@ibm.com>
License: The MIT License (MIT)
         
         Copyright © 2025 
         
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the “Software”), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in
         all copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         THE SOFTWARE.
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Operating System :: POSIX
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: MIT License
Requires-Dist: click>=8.3.0
Requires-Dist: rich>=14.2.0
Requires-Dist: sqlglot>=27.28.1
Requires-Python: >=3.10
Project-URL: Documentation, https://github.com/D3f0/sql-complexity#readme
Project-URL: Issues, https://github.com/D3f0/sql-complexity/issues
Project-URL: Source, https://github.com/D3f0/sql-complexity
Description-Content-Type: text/markdown

# 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](https://stackoverflow.com/questions/3353634/measuring-the-complexity-of-sql-statements) thread.


## Install

```bash
python -m pip install sql-complexity
```

```bash
poetry add sql-complexity
```

```bash
uv add sql-complexity
```

### Run with uvx

```bash
uvx --refresh sql-complexity
```

## Run from the CLI

```bash
sql-complexity some.sql
```

```bash
cat myfile.sql | sql-complexity
```

## Using it in your code

```python
from sql_complexity import SQLComplexityAssessment

assessor = SQLComplexityAssessment()
score = assessor.assess(contents)
print(score)
print(score.total)
```
