Skip to main content

django-print-sql is an easy-to-use SQL debug tool for Django developers to print SQL statements

What’s new

2018.3.6

  • Added a decorator

  • It now prints how long it takes each query to execute, as well as the total time elapsed

Requirements

You need to have django installed (obviously).

I’ve tried it on Django 1.11.11 and 2.0.3.

If sqlparse is installed, the SQL statement wil be formatted.

Install

From pip, run:

$ pip install --upgrade django-print-sql

Consider using the --user option.

From the repository, run:

python setup.py install

to install django-print-sql on your system.

django-print-sql is compatible with Python 2.7 and Python 3 (>= 3.3) (hopefully :D).

Install sqlparse to pretty print the statements:

$ pip install --upgrade sqlparse

Usage

Example 1. Use as context manager:

from django_print_sql import print_sql

# set `count_only` to `True` will print the number of executed SQL statements only
with print_sql(count_only=False):

  # write the code you want to analyze in here,
  # e.g. some complex foreign key lookup,
  # or analyzing a DRF serializer's performance

  for user in User.objects.all()[:10]:
      user.groups.first()

Example 2. Use as decorator:

from django_print_sql import print_sql_decorator


  @print_sql_decorator(count_only=False)  # this works on class-based views as well
  def get(request):
      # your view code here

Metadata

Release files for django-print-sql 2018.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-print-sql 2018.3.6
File Size Uploaded
django-print-sql-2018.3.6.tar.gz 3.1 kB Details

Release files / django-print-sql-2018.3.6.tar.gz

Download URL django-print-sql-2018.3.6.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
283a16b252b330a3009158a4b010f9db96c60380dcbdc4c2d2d8d2eba105c47e
BLAKE2b-256 checksum
How to use checksums
3e34a21c40a7ec37c8cdb4f1d593ec69601baab13bf27cde5574afab35dd5f7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2018.3.6 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page