semvec/pypi-packages huggingface dataset:
query-master-optimizer 0.1.0
Production-ready database query optimization and performance monitoring for Python
License: MIT
Requires Python: <4.0,>=3.10
Keywords: database, query, optimization, performance, orm, sql

# 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