Django Query Doctor: Slow Query Diagnoses & Fixes

I just shipped django-query-doctor — an open-source package that diagnoses slow Django ORM queries and prescribes exact code fixes with file:line references. pip install django-query-doctor Every Django developer knows the ritual. Page loads slow. Open the toolbar. Stare at SQL. Ctrl+F through views. 40 minutes later you find the missing select_related. Ship it. Next sprint, same thing. I got tired of being the detective. So I built the tool that does the detective work for you. What makes it different from debug-toolbar, silk, or nplusone: Those tools tell you WHAT queries ran. django-query-doctor tells you WHERE in your code the problem is, WHY it's slow, and gives you the exact fix — copy, paste, done. → N+1 in blog/views.py:42? Here's the select_related() call to add. → 15 duplicate queries? Here's the cache pattern to eliminate them. → SELECT * on 47 columns? Here's the .only() you need. → DRF serializer triggering hidden queries? Caught and explained. But detection was just the start: → python manage.py fix_queries — auto-patches your code (with dry-run preview) → python manage.py diagnose_project — scans every URL, scores every app → pytest plugin that fails your build if someone introduces an N+1 → CI mode that only flags queries in files YOUR PR touched → Celery, async/ASGI, OpenTelemetry, JSON + HTML reports → One line in settings.py. Zero config. Never crashes your app. 434 tests. 87% coverage. Python 3.10–3.13. Django 4.2–6.0. Built with Claude as my AI development partner — 42 source files, 44 test files, idea to PyPI in weeks instead of months. The architecture and decisions are mine, but I'm not going to pretend this scope was possible solo without AI. GitHub: https://lnkd.in/dPE59U5p PyPI: https://lnkd.in/dwXcJbg7 Try it on your slowest endpoint. Star it, break it, open issues. #Django #Python #OpenSource #DeveloperTools #BackendEngineering #BuildInPublic #AIAssistedDevelopment

  • text

Looks interesting How does it handle cases like these? 1. When you have nested serializers, does it also suggest updates to the get_queryset() used by the parent view? 2. If nested serializers contain methods (e.g., get_<field>) that trigger additional queries, will the tool suggest adding Prefetch, select_related, or annotations to avoid those extra requests? 3. Cases where a serializer method (e.g., get_<field>) just loops over another model/queryset. Does it detect that pattern and suggest a better approach?

slow page loads are often a review widget's fault, but sometimes it's the ORM queries running wild in the background — this tool could be a lifesaver for optimizing those, especially with the auto-patch feature, how's the performance impact when running django-query-doctor on larger codebases?

Looks great, will check this out! if I want to analyze queries for a specific .py file only, is there a way to run the diagnosis just for that file

Cool stuff Hassan Zaib Hayat Will check it out You should also check PyDoctor CLI that I also shipped few days ago. Pydoctor is a autonomous diagnostic CLI tool designed to analyze and diagnose the health of Python environments and projects. Check it out 👇 https://pydoctor.vercel.app/releases

Great, i will give it a trial and when done, i will drop feedback

Interesting. Have to try. Wanted to build something like this, now I won't have to. Will check this out for sure. Thanks.

Like
Reply

Great expect, it's good to use, just add AI in it

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories