capture-db-queries


Namecapture-db-queries JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/Friskes/capture-db-queries
SummaryDecorator for measuring the time and number of database queries
upload_time2024-05-02 17:19:32
maintainerNone
docs_urlNone
authorFriskes
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Friskes Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords django database
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Decorator for measuring the time and number of database queries

<div align="center">

| Project   |     | Status                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|-----------|:----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| CI/CD     |     | [![Latest Release](https://github.com/Friskes/capture-db-queries/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/Friskes/capture-db-queries/actions/workflows/publish-to-pypi.yml)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Quality   |     | [![Coverage](https://codecov.io/github/Friskes/capture-db-queries/graph/badge.svg?token=vKez4Pycrc)](https://codecov.io/github/Friskes/capture-db-queries)                                                                                                                                                                                                                                                                                                                               |
| Package   |     | [![PyPI - Version](https://img.shields.io/pypi/v/capture-db-queries?labelColor=202235&color=edb641&logo=python&logoColor=edb641)](https://badge.fury.io/py/capture-db-queries) ![PyPI - Support Python Versions](https://img.shields.io/pypi/pyversions/capture-db-queries?labelColor=202235&color=edb641&logo=python&logoColor=edb641) ![Project PyPI - Downloads](https://img.shields.io/pypi/dm/capture-db-queries?logo=python&label=downloads&labelColor=202235&color=edb641&logoColor=edb641)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| Meta      |     | [![types - Mypy](https://img.shields.io/badge/types-Mypy-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://github.com/python/mypy) [![License - MIT](https://img.shields.io/badge/license-MIT-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://spdx.org/licenses/) [![code style - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json&labelColor=202235)](https://github.com/astral-sh/ruff) |

</div>

> Provides a decorator for measuring the time and number of database queries

## Install
1. Install package
    ```bash
    pip install capture-db-queries
    ```

## About decorator
`capture_queries` decorator it can call the body of the decorated function the specified number of times for multiple measurements, it can validate the total number of queries.

- Optional parameters:
    - `assert_q_count`: The expected number of database requests is otherwise "AssertionError: N not less than or equal to N queries"
    - `number_runs`: The number of runs of the test function `_`
    - `verbose`: Displaying the final results of the test measurements
    - `advanced_verb`: Displaying the result of each test measurement
    - `queries`: Displaying raw SQL queries to the database

## About context manager
`ExtCaptureQueriesContext`

- Optional parameters:
    - `assert_q_count`: The expected number of database requests is otherwise "AssertionError: N not less than or equal to N queries"
    - `verbose`: Displaying the final results of the test measurements
    - `queries`: Displaying raw SQL queries to the database


## Usage example

```python
from capture_db_queries.decorators import capture_queries


@capture_queries(number_runs=2, advanced_verb=True)
def _():
    response = self.client.get(url)

>>> Test №1 | Queries count: 10 | Execution time: 0.04s
>>> Test №2 | Queries count: 10 | Execution time: 0.04s
>>> Tests count: 2  |  Total queries count: 20  |  Total execution time: 0.08s  |  Median time one test is: 0.041s
```

```python
from capture_db_queries.decorators import ExtCaptureQueriesContext


with ExtCaptureQueriesContext():
    response = self.client.get(url)

>>> Queries count: 164  |  Execution time: 0.923s
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Friskes/capture-db-queries",
    "name": "capture-db-queries",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "Django, Database",
    "author": "Friskes",
    "author_email": "Friskes <friskesx@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/51/7e/f302e1f50799be85af456ca321c9b76c10c438b54081db4cd7aaa5e9e46f/capture_db_queries-1.0.2.tar.gz",
    "platform": null,
    "description": "# Decorator for measuring the time and number of database queries\n\n<div align=\"center\">\n\n| Project   |     | Status                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |\n|-----------|:----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| CI/CD     |     | [![Latest Release](https://github.com/Friskes/capture-db-queries/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/Friskes/capture-db-queries/actions/workflows/publish-to-pypi.yml)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n| Quality   |     | [![Coverage](https://codecov.io/github/Friskes/capture-db-queries/graph/badge.svg?token=vKez4Pycrc)](https://codecov.io/github/Friskes/capture-db-queries)                                                                                                                                                                                                                                                                                                                               |\n| Package   |     | [![PyPI - Version](https://img.shields.io/pypi/v/capture-db-queries?labelColor=202235&color=edb641&logo=python&logoColor=edb641)](https://badge.fury.io/py/capture-db-queries) ![PyPI - Support Python Versions](https://img.shields.io/pypi/pyversions/capture-db-queries?labelColor=202235&color=edb641&logo=python&logoColor=edb641) ![Project PyPI - Downloads](https://img.shields.io/pypi/dm/capture-db-queries?logo=python&label=downloads&labelColor=202235&color=edb641&logoColor=edb641)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |\n| Meta      |     | [![types - Mypy](https://img.shields.io/badge/types-Mypy-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://github.com/python/mypy) [![License - MIT](https://img.shields.io/badge/license-MIT-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://spdx.org/licenses/) [![code style - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json&labelColor=202235)](https://github.com/astral-sh/ruff) |\n\n</div>\n\n> Provides a decorator for measuring the time and number of database queries\n\n## Install\n1. Install package\n    ```bash\n    pip install capture-db-queries\n    ```\n\n## About decorator\n`capture_queries` decorator it can call the body of the decorated function the specified number of times for multiple measurements, it can validate the total number of queries.\n\n- Optional parameters:\n    - `assert_q_count`: The expected number of database requests is otherwise \"AssertionError: N not less than or equal to N queries\"\n    - `number_runs`: The number of runs of the test function `_`\n    - `verbose`: Displaying the final results of the test measurements\n    - `advanced_verb`: Displaying the result of each test measurement\n    - `queries`: Displaying raw SQL queries to the database\n\n## About context manager\n`ExtCaptureQueriesContext`\n\n- Optional parameters:\n    - `assert_q_count`: The expected number of database requests is otherwise \"AssertionError: N not less than or equal to N queries\"\n    - `verbose`: Displaying the final results of the test measurements\n    - `queries`: Displaying raw SQL queries to the database\n\n\n## Usage example\n\n```python\nfrom capture_db_queries.decorators import capture_queries\n\n\n@capture_queries(number_runs=2, advanced_verb=True)\ndef _():\n    response = self.client.get(url)\n\n>>> Test \u21161 | Queries count: 10 | Execution time: 0.04s\n>>> Test \u21162 | Queries count: 10 | Execution time: 0.04s\n>>> Tests count: 2  |  Total queries count: 20  |  Total execution time: 0.08s  |  Median time one test is: 0.041s\n```\n\n```python\nfrom capture_db_queries.decorators import ExtCaptureQueriesContext\n\n\nwith ExtCaptureQueriesContext():\n    response = self.client.get(url)\n\n>>> Queries count: 164  |  Execution time: 0.923s\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Friskes  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Decorator for measuring the time and number of database queries",
    "version": "1.0.2",
    "project_urls": {
        "Changelog": "https://github.com/Friskes/capture-db-queries/releases/",
        "Homepage": "https://github.com/Friskes/capture-db-queries",
        "Issues": "https://github.com/Friskes/capture-db-queries/issues"
    },
    "split_keywords": [
        "django",
        " database"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "754f24b59b72655fe8f604bc1bb5deb09e520afff5ebbdc8c95900aa0884796e",
                "md5": "6bb5bc8a23a1de72483dde9fba1172cc",
                "sha256": "35bda975a9d0ee77726ae8126a39513f9008cdeba6736018dc25cbbc13139479"
            },
            "downloads": -1,
            "filename": "capture_db_queries-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6bb5bc8a23a1de72483dde9fba1172cc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7233,
            "upload_time": "2024-05-02T17:19:30",
            "upload_time_iso_8601": "2024-05-02T17:19:30.936436Z",
            "url": "https://files.pythonhosted.org/packages/75/4f/24b59b72655fe8f604bc1bb5deb09e520afff5ebbdc8c95900aa0884796e/capture_db_queries-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "517ef302e1f50799be85af456ca321c9b76c10c438b54081db4cd7aaa5e9e46f",
                "md5": "25cb6b2567280f12dfbea65b9bf6bb4f",
                "sha256": "4a13f08b60ac3bbc3c144ace159a75091f76d4bd2de8d2a2eba826e85464e7ed"
            },
            "downloads": -1,
            "filename": "capture_db_queries-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "25cb6b2567280f12dfbea65b9bf6bb4f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16579,
            "upload_time": "2024-05-02T17:19:32",
            "upload_time_iso_8601": "2024-05-02T17:19:32.067703Z",
            "url": "https://files.pythonhosted.org/packages/51/7e/f302e1f50799be85af456ca321c9b76c10c438b54081db4cd7aaa5e9e46f/capture_db_queries-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-02 17:19:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Friskes",
    "github_project": "capture-db-queries",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "capture-db-queries"
}
        
Elapsed time: 0.26334s