Decorator for measuring the time and number of database queries
Project description
Class that supports the function of decorator, iterator and context manager for measuring the time and number of database queries
Class that supports the function of decorator, iterator and context manager for measuring the time and number of database queries
Install
- Install package
pip install capture-db-queries
About decorator
CaptureQueries
class as decorator can call the body of the decorated function or class as iterator can run code inside for loop the specified number of times for multiple measurements, it can validate the total number of queries.
The functionality of the classic context manager is also available.
- 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 / test for loopverbose
: Displaying the final results of the test measurementsadvanced_verb
: Displaying the result of each test measurementauto_call_func
: Autorun of the decorated function (without arguments)queries
: Displaying raw SQL queries to the databaseconnection
: Connecting to your database, by default: django.db.connection
Usage examples
from capture_db_queries.decorators import CaptureQueries
for ctx in CaptureQueries(number_runs=2, advanced_verb=True):
response = self.client.get(url)
# OR
@CaptureQueries(number_runs=2, advanced_verb=True)
def test_request():
response = self.client.get(url)
# OR
# NOTE: The with context manager does not support multi-launch number_runs > 1
with CaptureQueries(number_runs=1, advanced_verb=True) as ctx:
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 | Vendor: sqlite
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file capture_db_queries-1.1.1.tar.gz
.
File metadata
- Download URL: capture_db_queries-1.1.1.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afdb0511b7400fd838dace33f7c8866cd4b7c223ae23c20394be5457b35ad203 |
|
MD5 | 8a8b0e67fc4d3ca59f9048f015aab701 |
|
BLAKE2b-256 | 9392420daddc13d52b12423af5f7132118b7335aa45446868aedb0171f32aa52 |
Provenance
The following attestation bundles were made for capture_db_queries-1.1.1.tar.gz
:
Publisher:
publish-to-pypi.yml
on Friskes/capture-db-queries
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
capture_db_queries-1.1.1.tar.gz
- Subject digest:
afdb0511b7400fd838dace33f7c8866cd4b7c223ae23c20394be5457b35ad203
- Sigstore transparency entry: 150088224
- Sigstore integration time:
- Predicate type:
File details
Details for the file capture_db_queries-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: capture_db_queries-1.1.1-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0f92accbd5b98ee219ff7e90759d4856d003573c88a8e7213d356be4ba30f1a |
|
MD5 | e6e3aa852a7460e4e314b197a0f7c814 |
|
BLAKE2b-256 | ccd7eab9ff9c8aaca9da2aad7816d2048660e4c9915fb6b79699b791621b6312 |
Provenance
The following attestation bundles were made for capture_db_queries-1.1.1-py3-none-any.whl
:
Publisher:
publish-to-pypi.yml
on Friskes/capture-db-queries
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
capture_db_queries-1.1.1-py3-none-any.whl
- Subject digest:
e0f92accbd5b98ee219ff7e90759d4856d003573c88a8e7213d356be4ba30f1a
- Sigstore transparency entry: 150088226
- Sigstore integration time:
- Predicate type: