A lightweight Django library that helps you optimize your app's database access.
Project description
Django-Turntable
This is a lightweight Django library that helps developers optimize their app's database access.
With Django’s ORM, it’s very easy to write code that executes a lot of redundant database queries, or to create queries that are very slow. This library can track all queries that are executed within a block of code, then:
- Tell you how many queries were executed
- Tell you how long those queries took to execute
- Warn you if the same query is executed repeatedly (the “N+1 selects problem”)
Here’s an example of what the output looks like (with logging.basicConfig()):
INFO:django_turntable:12 queries executed (0.364ms)
WARNING:django_turntable:Repeating query (10x): SELECT "music_artist"."id", "music_artist"."name" FROM "music_artist" WHERE "music_artist"."id" = %s LIMIT 21
Documentation
Context Manager
Use inspect_queries() as a context manager to examine all query usage within the body of the with statement. A summary will be logged when exiting the block (even if an exception occurs).
from django_turntable import inspect_queries
with inspect_queries():
...
Decorator
inspect_queries() can also be used as a function decorator.
from django_turntable import inspect_queries
@inspect_queries()
def some_function():
...
Middleware
Use the TurntableMiddleware to monitor query usage in your views, as well as any middleware placed below TurntableMiddleware.
MIDDLEWARE = [
'django_turntable.TurntableMiddleware',
]
Because this library is intended as a development tool, the middleware will automatically remove itself if the DEBUG setting is set to False.
Logging
All output is sent to the django_turntable logger. In your logging configuration, you should set this logger's level to INFO if you want to see all query usage, or WARNING if you just want to see potential problems.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_turntable-0.2.0.tar.gz.
File metadata
- Download URL: django_turntable-0.2.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb91338e72ee2c83a6efa61921461d54fda49cccd6d2806e5725fc91b92db5a6
|
|
| MD5 |
6e79c4fdd5b30eca7108e4a980d15eb6
|
|
| BLAKE2b-256 |
2a35a51f84c5b53be914a3dfc5aab854a203e8f8211f3d20e9cfaa3a04772f77
|
File details
Details for the file django_turntable-0.2.0-py3-none-any.whl.
File metadata
- Download URL: django_turntable-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb16af7a869d5a533ecbfc23c259f49d1c1cc5676b615402860c54e7b40dc6b6
|
|
| MD5 |
b3e4f32a8f39a4afbb2bdb35c23415d6
|
|
| BLAKE2b-256 |
b48f8fd733f1ada4c526f1104997b887b3daebe475a32d226b79bb33be6a4d0a
|