{"id":18444634,"url":"https://github.com/conformist-mw/django-query-counter","last_synced_at":"2025-04-03T03:10:15.213Z","repository":{"id":42200888,"uuid":"359588521","full_name":"conformist-mw/django-query-counter","owner":"conformist-mw","description":"Simple tool to count Django db queries in the management commands and views (as decorator or middleware)","archived":false,"fork":false,"pushed_at":"2025-03-16T18:25:56.000Z","size":66,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T02:37:28.751Z","etag":null,"topics":["debug","decorator","django","duplicated-queries","middleware"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-query-counter/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/conformist-mw.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md"}},"created_at":"2021-04-19T20:24:48.000Z","updated_at":"2025-03-16T18:26:00.000Z","dependencies_parsed_at":"2023-11-13T13:40:50.257Z","dependency_job_id":"0cb54d19-f704-49c0-90b8-a9db8a873ba6","html_url":"https://github.com/conformist-mw/django-query-counter","commit_stats":{"total_commits":37,"total_committers":5,"mean_commits":7.4,"dds":0.2702702702702703,"last_synced_commit":"b06659f946c32cd6e4f747086e284ae62c7477c5"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conformist-mw%2Fdjango-query-counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conformist-mw%2Fdjango-query-counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conformist-mw%2Fdjango-query-counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conformist-mw%2Fdjango-query-counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/conformist-mw","download_url":"https://codeload.github.com/conformist-mw/django-query-counter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246927835,"owners_count":20856198,"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":["debug","decorator","django","duplicated-queries","middleware"],"created_at":"2024-11-06T07:03:00.993Z","updated_at":"2025-04-03T03:10:15.204Z","avatar_url":"https://github.com/conformist-mw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Queries Count\n\n[![check](https://github.com/conformist-mw/django-query-counter/actions/workflows/check.yml/badge.svg)](https://github.com/conformist-mw/django-query-counter/actions/workflows/check.yml)\n[![PyPI version](https://badge.fury.io/py/django-query-counter.svg)](https://badge.fury.io/py/django-query-counter)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-query-counter)\n![PyPI - Versions from Framework Classifiers](https://img.shields.io/pypi/frameworkversions/django/django-query-counter)\n\n\nThe difference between this project and all the others like it is that I needed\n to debug management command in Django, but all the others only provided middleware,\n which did not solve my problem.\n\n## Example output\n\n![duplicates-main-example](https://user-images.githubusercontent.com/13550539/117552176-89c30b80-b052-11eb-80b9-7eb32435d116.png)\n\nThe basic idea is to count duplicate queries, like django-debug-toolbar does,\n and output them. The number of duplicated queries and the color of the theme\n can be specified in the settings. It is also possible to output all requests\n at once (counted if they are duplicated).\n\n## Content\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Available settings](#available-settings)\n- [Additional screenshots](#additional-screenshots)\n- [Contribute](#contribute)\n\n## Installation\n\nIt is enough to install the package and apply the decorator to the desired\n management command or view.\n\n```shell\npip install django-query-counter\n```\n\nPlease take note that the colored and reformatted SQL output depicted in\nthe readme screenshots may not be achieved unless the specified additional\npackages are installed (which maybe already installed):\n\n- colorize requires [pygments](https://pypi.org/project/Pygments/)\n\n```shell\npip install Pygments\n```\n\n- reformat requires [sqlparse](https://pypi.org/project/sqlparse/)\n\n```shell\npip install sqlparse\n```\n\n## Usage\n\nThe project can be used in two ways:\n\nImport the decorator and apply it where you need to know the number of queries\n to the database.\n\n- management command:\n\n ```python\nfrom django.core.management.base import BaseCommand\nfrom query_counter.decorators import queries_counter\n\nclass Command(BaseCommand):\n\n    @queries_counter\n    def handle(self, *args, **options):\n        pass\n ```\n\n- function-based views\n\n```python\nfrom query_counter.decorators import queries_counter\n\n\n@queries_counter\ndef index(request):\n    pass\n```\n\n- class-based views:\n\n```python\nfrom django.utils.decorators import method_decorator\nfrom query_counter.decorators import queries_counter\n\n\n@method_decorator(queries_counter, name='dispatch')\nclass IndexView(View):\n    pass\n```\n\n- specifying middleware in settings for all views at once.\n\n```python\nMIDDLEWARE = [\n    'query_counter.middleware.DjangoQueryCounterMiddleware',\n]\n```\n\n### Available settings\n\nIt is possible to override the default settings. To do this, you need to\n include the app to the INSTALLED_APPS:\n\n```python\nINSTALLED_APPS = [\n    ...,\n    'query_counter',\n    ...\n]\n```\n\nDefault settings:\n\n```python\n{\n    'DQC_SLOWEST_COUNT': 5,\n    'DQC_TABULATE_FMT': 'pretty',\n    'DQC_SLOW_THRESHOLD': 1,  # seconds\n    'DQC_INDENT_SQL': True,\n    'DQC_PYGMENTS_STYLE': 'tango',\n    'DQC_PRINT_ALL_QUERIES': False,\n    'DQC_COUNT_QTY_MAP': {\n        5: 'green',\n        10: 'white',\n        20: 'yellow',\n        30: 'red',\n    },\n}\n```\n\nFeel free to override any of them.\n\nTabulate tables formats you can find [here](https://github.com/astanin/python-tabulate#table-format).\nPygments styles available [here](https://pygments.org/demo/).\n\n### Additional screenshots\n\n![good_example](https://user-images.githubusercontent.com/13550539/117552177-8a5ba200-b052-11eb-8b6b-e66521aebdd6.png)\n![yellow_example](https://user-images.githubusercontent.com/13550539/117552179-8af43880-b052-11eb-85ca-65df4eca3ea7.png)\n\n### Contribute\n\nFeel free to open an issue to report of any bugs. Bug fixes and features are\n welcome! Be sure to add yourself to the AUTHORS.md if you provide PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconformist-mw%2Fdjango-query-counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconformist-mw%2Fdjango-query-counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconformist-mw%2Fdjango-query-counter/lists"}