Metadata-Version: 2.3
Name: sql-complexity
Version: 0.1.3
Summary: Add your description here
Author: Nahuel Defossé
Author-email: Nahuel Defossé <nahuel.deofsse@ibm.com>
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
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)
```
