slowquery-detective
Catch slow Postgres queries live. Fingerprint the pattern. Run
EXPLAINasynchronously. Suggest the index. A drop-in FastAPI + SQLAlchemy middleware.
What it does
- Fingerprints every query via
sqlglot—WHERE id=1andWHERE id=2collapse into one row, so you see the pattern that's slow. - Runs
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)asynchronously for queries that cross the p95 threshold, off the request path. - Suggests fixes via a deterministic rules engine (seq-scan on large tables, missing FK indexes, sort without index, function in WHERE,
SELECT *, N+1). When no rule matches, an OpenRouter-backed LLM explains the plan in plain English. - Exposes a tiny dashboard API (optional router) so a frontend can render live p95 timelines and one-click index suggestions.
This repository is the PyPI package only. The demo service and dashboard live in:
Abdul-Muizz1310/slowquery-demo-backend— feathers-generated FastAPI service with a seeded 1M-row datasetAbdul-Muizz1310/slowquery-dashboard-frontend— Next.js dashboard
3-line integration
from slowquery_detective import install
install(app, engine)
Optional: mount the dashboard API on the same app.
from slowquery_detective import install, dashboard_router
install(app, engine)
app.include_router(dashboard_router, prefix="/_slowquery")
Status: this repo is at Phase 4a S1 — Bootstrap. The
installhelper is defined bydocs/specs/05-middleware.mdand lands in S3. Seedocs/ARCHITECTURE.mdfor the component map anddocs/DEMO.mdfor the reproduction script.
Install
pip install slowquery-detective[fastapi]
# or, to enable the LLM fallback:
pip install slowquery-detective[fastapi,llm]
Development
git clone https://github.com/Abdul-Muizz1310/slowquery-detective
cd slowquery-detective
uv sync --all-extras
uv run pytest
uv run ruff check .
uv run mypy src/
License
MIT — see LICENSE.
Metadata
Release files for slowquery-detective 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| slowquery_detective-0.1.0.tar.gz | 20.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| slowquery_detective-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 50.0 kB
Release files / slowquery_detective-0.1.0.tar.gz
| Download URL | slowquery_detective-0.1.0.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6cb0ef06ded862c544d0ce4aec9ee86c71df8010654cacd6f9fa456c86c3c60
|
|
BLAKE2b-256 checksum How to use checksums |
97dd1cc5547f383cc68b90a76763b93ba1734ef7432911eeacffae21a2a0a678
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / slowquery_detective-0.1.0-py3-none-any.whl
| Download URL | slowquery_detective-0.1.0-py3-none-any.whl |
|---|---|
| Size | 29.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b57fe0646a794dcc4894b98d587c6861d3b9c3ed3510c4ac304914317b643283
|
|
BLAKE2b-256 checksum How to use checksums |
99369f0792e2d504d3688fdae86a4ada3e9ebd73d9737a0901daf94dedae2563
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|