django-query-counter


Namedjango-query-counter JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/conformist-mw/django-query-counter
SummaryDebug tool to print sql queries count to the console
upload_time2023-11-14 08:42:01
maintainer
docs_urlNone
authorOleg Smedyuk
requires_python
licenseMIT
keywords django sql query count management commands
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Queries Count

[![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)
[![PyPI version](https://badge.fury.io/py/django-query-counter.svg)](https://badge.fury.io/py/django-query-counter)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-query-counter)
![PyPI - Versions from Framework Classifiers](https://img.shields.io/pypi/frameworkversions/django/django-query-counter)


The difference between this project and all the others like it is that I needed
 to debug management command in Django, but all the others only provided middleware,
 which did not solve my problem.

## Example output

![duplicates-main-example](https://user-images.githubusercontent.com/13550539/117552176-89c30b80-b052-11eb-80b9-7eb32435d116.png)

The basic idea is to count duplicate queries, like django-debug-toolbar does,
 and output them. The number of duplicated queries and the color of the theme
 can be specified in the settings. It is also possible to output all requests
 at once (counted if they are duplicated).

## Content

- [Installation](#installation)
- [Usage](#usage)
- [Available settings](#available-settings)
- [Additional screenshots](#additional-screenshots)
- [Contribute](#contribute)

## Installation

It is enough to install the package and apply the decorator to the desired
 management command or view.

```shell
pip install django-query-counter
```

## Usage

The project can be used in two ways:

Import the decorator and apply it where you need to know the number of queries
 to the database.

- management command:

 ```python
from django.core.management.base import BaseCommand
from query_counter.decorators import queries_counter

class Command(BaseCommand):

    @queries_counter
    def handle(self, *args, **options):
        pass
 ```

- function-based views

```python
from query_counter.decorators import queries_counter


@queries_counter
def index(request):
    pass
```

- class-based views:

```python
from django.utils.decorators import method_decorator
from query_counter.decorators import queries_counter


@method_decorator(queries_counter, name='dispatch')
class IndexView(View):
    pass
```

- specifying middleware in settings for all views at once.

```python
MIDDLEWARE = [
    'query_counter.middleware.DjangoQueryCounterMiddleware',
]
```

### Available settings

It is possible to override the default settings. To do this, you need to
 include the app to the INSTALLED_APPS:

```python
INSTALLED_APPS = [
    ...,
    'query_counter',
    ...
]
```

Default settings:

```python
{
    'DQC_SLOWEST_COUNT': 5,
    'DQC_TABULATE_FMT': 'pretty',
    'DQC_SLOW_THRESHOLD': 1,  # seconds
    'DQC_INDENT_SQL': True,
    'DQC_PYGMENTS_STYLE': 'tango',
    'DQC_PRINT_ALL_QUERIES': False,
    'DQC_COUNT_QTY_MAP': {
        5: 'green',
        10: 'white',
        20: 'yellow',
        30: 'red',
    },
}
```

Feel free to override any of them.

Tabulate tables formats you can find [here](https://github.com/astanin/python-tabulate#table-format).
Pygments styles available [here](https://pygments.org/demo/).

### Additional screenshots

![good_example](https://user-images.githubusercontent.com/13550539/117552177-8a5ba200-b052-11eb-8b6b-e66521aebdd6.png)
![yellow_example](https://user-images.githubusercontent.com/13550539/117552179-8af43880-b052-11eb-85ca-65df4eca3ea7.png)

### Contribute

Feel free to open an issue to report of any bugs. Bug fixes and features are
 welcome! Be sure to add yourself to the AUTHORS.md if you provide PR.

#### Release

```shell
python setup.py sdist bdist_wheel
twine check dist/*
twine upload dist/*
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/conformist-mw/django-query-counter",
    "name": "django-query-counter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django sql query count management commands",
    "author": "Oleg Smedyuk",
    "author_email": "oleg.smedyuk@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b2/98/7f34cdbb0092ceca3c2b5bc063d5c055af6188886e2e40e6822209d46976/django-query-counter-0.4.0.tar.gz",
    "platform": null,
    "description": "# 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\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\n#### Release\n\n```shell\npython setup.py sdist bdist_wheel\ntwine check dist/*\ntwine upload dist/*\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Debug tool to print sql queries count to the console",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/conformist-mw/django-query-counter"
    },
    "split_keywords": [
        "django",
        "sql",
        "query",
        "count",
        "management",
        "commands"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ce7f277ad30546cbf5cbff1792f5de29c2e8630cdb2f4a09ce785cc950bb8e31",
                "md5": "6dbad9bfbdfcfb74623714bb1f29b561",
                "sha256": "ad85e03671f7b63ed6eb126244c7bb552249901611d7765dfa975657bf586fbf"
            },
            "downloads": -1,
            "filename": "django_query_counter-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6dbad9bfbdfcfb74623714bb1f29b561",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7642,
            "upload_time": "2023-11-14T08:42:00",
            "upload_time_iso_8601": "2023-11-14T08:42:00.430308Z",
            "url": "https://files.pythonhosted.org/packages/ce/7f/277ad30546cbf5cbff1792f5de29c2e8630cdb2f4a09ce785cc950bb8e31/django_query_counter-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b2987f34cdbb0092ceca3c2b5bc063d5c055af6188886e2e40e6822209d46976",
                "md5": "7a83b7d71b8432594006bb81e84e6206",
                "sha256": "0bb84eef7ae0c39034ae1d3d2fc3e419f86d115d78f5d0805cd036a8907c150c"
            },
            "downloads": -1,
            "filename": "django-query-counter-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7a83b7d71b8432594006bb81e84e6206",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7387,
            "upload_time": "2023-11-14T08:42:01",
            "upload_time_iso_8601": "2023-11-14T08:42:01.861024Z",
            "url": "https://files.pythonhosted.org/packages/b2/98/7f34cdbb0092ceca3c2b5bc063d5c055af6188886e2e40e6822209d46976/django-query-counter-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-14 08:42:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "conformist-mw",
    "github_project": "django-query-counter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-query-counter"
}
        
Elapsed time: 0.24732s