Metadata-Version: 2.1
Name: query-master-optimizer
Version: 0.1.0
Summary: Production-ready database query optimization and performance monitoring for Python
Home-page: https://github.com/amilalizada/query-master
License: MIT
Keywords: database,query,optimization,performance,orm,sql
Author: Amil Alizada
Author-email: amilalizada@gmail.com
Requires-Python: >=3.10,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Database
Provides-Extra: django
Provides-Extra: fastapi
Provides-Extra: flask
Provides-Extra: peewee
Provides-Extra: sqlalchemy
Requires-Dist: django (>=3.2) ; extra == "django"
Requires-Dist: fastapi (>=0.100) ; extra == "fastapi"
Requires-Dist: flask (>=2.0) ; extra == "flask"
Requires-Dist: peewee (>=3.0) ; extra == "peewee"
Requires-Dist: sqlalchemy (>=1.4) ; extra == "sqlalchemy"
Requires-Dist: typing-extensions (>=4.0) ; python_version < "3.10"
Project-URL: Repository, https://github.com/amilalizada/query-master
Description-Content-Type: text/markdown

# QueryMaster

Production-ready database query optimization and performance monitoring for Python applications.

## Features

- **Query analysis**: N+1 detection, full table scan hints, complexity, slow query flagging
- **Performance monitoring**: In-memory query history, stats, terminal dashboard
- **Optimization engine**: Suggestions and index advisor based on WHERE/JOIN columns
- **Integrations**: Generic cursor wrapper, SQLAlchemy events, context manager for raw SQL

## Installation

This package is published on PyPI as **query-master-optimizer** (the name "querymaster" is already taken). You still import it as `querymaster`:

```bash
pip install query-master-optimizer
```

Optional extras:

```bash
pip install query-master-optimizer[sqlalchemy]   # SQLAlchemy engine recording
pip install query-master-optimizer[django]       # Django (future)
pip install query-master-optimizer[fastapi]      # FastAPI (optional)
pip install query-master-optimizer[flask]        # Flask (optional)
```

## Quick Start

```python
from querymaster import (
    QueryRecorder,
    QueryMasterConfig,
    analyze_query,
    print_dashboard,
)

# Configure and create recorder
config = QueryMasterConfig(slow_query_threshold_ms=50.0)
recorder = QueryRecorder(config)

# Record some queries (e.g. from your app)
recorder.record("SELECT * FROM users WHERE id = 1", execution_time_ms=12.5)
recorder.record("SELECT * FROM orders WHERE user_id = 1", execution_time_ms=120.0)

# Analyze a single query
issues = analyze_query(
    "SELECT * FROM users WHERE 1=1",
    execution_time=0.5,
)
for issue in issues:
    print(issue.message, issue.suggestion)

# Print terminal dashboard
print_dashboard(recorder)
```

## SQLAlchemy Integration

```python
from sqlalchemy import create_engine
from querymaster import QueryRecorder
from querymaster.integrations.sqlalchemy_events import install_sqlalchemy

engine = create_engine("postgresql://...")
recorder = QueryRecorder()
install_sqlalchemy(engine, recorder)
# All statements executed via this engine are now recorded
```

## License

MIT

