{"id":13415882,"url":"https://github.com/django-query-profiler/django-query-profiler","last_synced_at":"2025-03-14T23:31:13.827Z","repository":{"id":38271824,"uuid":"222863917","full_name":"django-query-profiler/django-query-profiler","owner":"django-query-profiler","description":"Django query profiler - one profiler to rule them all.  Shows queries, detects N+1 and gives recommendations on how to resolve them","archived":false,"fork":false,"pushed_at":"2022-11-25T06:48:19.000Z","size":13405,"stargazers_count":140,"open_issues_count":4,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-30T23:12:40.731Z","etag":null,"topics":["django","django-extensions","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/django-query-profiler.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-20T06:10:41.000Z","updated_at":"2024-09-19T09:35:38.000Z","dependencies_parsed_at":"2023-01-21T22:04:26.540Z","dependency_job_id":null,"html_url":"https://github.com/django-query-profiler/django-query-profiler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-query-profiler%2Fdjango-query-profiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-query-profiler%2Fdjango-query-profiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-query-profiler%2Fdjango-query-profiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/django-query-profiler%2Fdjango-query-profiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/django-query-profiler","download_url":"https://codeload.github.com/django-query-profiler/django-query-profiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243663459,"owners_count":20327299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-extensions","python3"],"created_at":"2024-07-30T21:00:52.771Z","updated_at":"2025-03-14T23:31:11.148Z","avatar_url":"https://github.com/django-query-profiler.png","language":"Python","funding_links":[],"categories":["Third-Party Packages"],"sub_categories":["Performance"],"readme":"======================\nDjango Query Profiler\n======================\n\n.. image:: https://img.shields.io/pypi/l/django.svg\n   :target: https://raw.githubusercontent.com/django-query-profiler/django-query-profiler/master/LICENSE\n\n.. image:: https://travis-ci.com/django-query-profiler/django-query-profiler.svg?branch=master\n    :target: https://travis-ci.com/django-query-profiler/django-query-profiler\n\n.. image:: https://codecov.io/gh/django-query-profiler/django-query-profiler/branch/master/graph/badge.svg?token=1Cv7WsOi2W\n  :target: https://codecov.io/gh/django-query-profiler/django-query-profiler\n\n.. image:: https://readthedocs.org/projects/django-query-profiler/badge/?version=latest\n  :target: https://django-query-profiler.readthedocs.io/en/latest/index.html\n\n.. image:: https://img.shields.io/pypi/pyversions/django-query-profiler.svg\n  :target: https://pypi.org/project/django-query-profiler/\n\n.. image:: https://img.shields.io/pypi/djversions/django-query-profiler\n  :target: https://pypi.org/project/django-query-profiler/\n\n.. image:: https://badge.fury.io/py/django-query-profiler.svg\n    :target: https://pypi.org/project/django-query-profiler/\n\n\n\nThis is a query profiler for Django applications, for helping developers answer the question \"My Django code/page/API is slow, How do I find out why?\"\n\nBelow are some of the features of the profiler:\n\n1. Shows code paths making N+1 sql calls:  Shows the sql with stack_trace which is making N+1 calls, along with sql count\n2. Shows the proposed solution: If the solution to reduce sql is to simply apply a select_related or a prefetch_related, this is highlighted as a suggestion\n3. Shows exact sql duplicates: Count of the queries where (sql, parameters) is exactly the same.  This is the kind of sql where implementing a query cache would help\n4. Flame Graph visualisation: Collects all the stack traces together to allow quickly identifying which area(s) of code is causing the load to the database\n5. Command line or chrome plugin: The profiler can be called from command line via context manager, or can be invoked via a middleware, and output shown in a chrome plugin\n6. Super easy to configure in any application:  The only changes are in settings.py file and in urls.py file\n\nThis is the `repo \u003chttps://github.com/django-query-profiler/django-query-profiler-chrome-plugin\u003e`_ for the chrome plugin\n\nRequirements\n============\n\nThis works with any version of django \u003e= 2.0, and running on python \u003e= 3.6\n\n\nProfiler in Action\n==================\n\nas a chrome plugin\n------------------\n\nThis image shows how the chrome plugin would display profiled data, once it is configured \u0026 installed\n\n.. image:: https://raw.githubusercontent.com/django-query-profiler/django-query-profiler/master/docs/_static/django_query_profiler_in_action.gif\n\non command line\n---------------\n\nSee this `file\n\u003chttps://github.com/django-query-profiler/django-tip-02/blob/18785d9e44b5f542ce26f555a4bcf18124f788d0/DJANGO_QUERY_PROFILER.md\u003e`_ in the PR to see how to use the context manager, and how easy it is to find performance issues :-)\n\nThe output of Django query profiler is same for the command line or the chrome plugin.   In fact, chrome plugin displays the output set by the middleware - which is just a plain wrapper around context manager.\n\nGetting Started\n===============\n\ninstallation\n------------\n\nThe simplest way to getting started is to install the django query profiler from pip, and get the chrome plugin from\nchrome web store.\n\n**Python package:**\n\n.. code-block:: console\n\n  pip install django-query-profiler\n\n**Chrome Plugin:**\n\nDownload from `chrome webstore \u003chttps://chrome.google.com/webstore/detail/django-query-profiler/ejdgfhecpkhdnpdmdheacfmknaegicff\u003e`__\n\n\nThis is covered in detail in the `installation \u003chttps://django-query-profiler.readthedocs.io/en/latest/installation.html\u003e`__ section in the docs\n\nconfiguration:\n--------------\n\nThis configuration is when we want to use the profiler along with the chrome plugin.  If we want to just use it on the\ncommand line, the configuration is much more simpler (two lines of change to settings.py file) - that is covered in the `docs \u003chttps://django-query-profiler.readthedocs.io/en/latest/configuration_instructions.html#as-context-manager\u003e`__\n\n**settings.py:**\n\n.. code-block:: python\n\n    from django_query_profiler.settings import *\n\n    INSTALLED_APPS = (\n        ...\n        'django_query_profiler',\n        ...\n    )\n\n    MIDDLEWARE = (\n        ...\n         # Request and all middleware that come after our middleware, would be profiled\n        'django_query_profiler.client.middleware.QueryProfilerMiddleware',\n        ...\n    )\n\n    DATABASES = (\n        ...\n        # Adding django_query_profiler as a prefix to your ENGINE setting\n        # Assuming old ENGINE was \"django.db.backends.sqlite3\", this would be the new one\n        \"ENGINE\": \"django_query_profiler.django.db.backends.sqlite3\",\n    )\n\n\n**urls.py:**\n\n.. code-block:: python\n\n  # Add this line to existing urls.py\n  path('django_query_profiler/', include('django_query_profiler.client.urls'))\n\n\nSee this `PR\n\u003chttps://github.com/django-query-profiler/django-query-profiler-sample-app/pull/1\u003e`__ on how to configure this in your application,\nand how the plugin is going to look like after your configuration\n\n.. image:: https://raw.githubusercontent.com/django-query-profiler/django-query-profiler/master/docs/_static/chrome_plugin.png\n\n\nThis is covered in detail in the `configuration instructions \u003chttps://django-query-profiler.readthedocs.io/en/latest/configuration_instructions.html\u003e`__ section in the docs\n\nHow the profiler works\n======================\n\nThis is also covered in detail in the documentation at `how the profiler works \u003chttps://django-query-profiler.readthedocs.io/en/latest/how_it_works.html\u003e`__ section in the docs,\nalong with how the code is organized.\n\nThe docs also contain references to various links which helped us to lear about internals of Django, and to various projects which helped us to learn on how to add hooks when Django executes a query\n\n\nChoosing Profiler levels\n========================\n\nWe have two levels of profiler, and each of them have a different overhead.  The two levels are:\n\n1. QUERY_SIGNATURE:   This is the mode where we capture the query as well as the stack-trace.  This mode figures out the N+1 code paths and also tells us the proposed solution\n2. QUERY: This is the mode where we just capture queries, and not the stack-trace\n\nOn an average, QUERY_SIGNATURE level adds an overhead of `1 millisecond per 7 queries`, and QUERY_SIGNATURE adds an overhead of `1 millisecond per 25 queries`.\n\nIt is simple to change the profiler level for all the requests, or can be configured per request.  This is covered in the `choosing profiler level \u003chttps://django-query-profiler.readthedocs.io/en/latest/choosing_profiler_level.html\u003e`__ section of the docs\n\nCustomizing the profiler\n========================\n\nWe have tried to make the profiler customizable by providing hooks at various points.   Some of the use cases are covered\nhere in the `customizing the defaults \u003chttps://django-query-profiler.readthedocs.io/en/latest/customizing_defaults.html\u003e`__ section in docs.\n\nWe plan to add more hooks for customizing the profiler as we gather more feedback from real world use cases.\n\n\nFor contributors\n================\n\n.. image:: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square\n   :target: http://makeapullrequest.com\n\nThe django query profiler is released under the BSD license, like Django itself.\n\nIf you like it, please consider contributing!  The docs cover everything from how to setup locally, to how the code is organized to running tests.\n\n\nDocumentation\n=============\n\nFull documentation is available at `readthedocs \u003chttps://django-query-profiler.readthedocs.io/en/latest/index.html\u003e`__\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjango-query-profiler%2Fdjango-query-profiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjango-query-profiler%2Fdjango-query-profiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjango-query-profiler%2Fdjango-query-profiler/lists"}