Skip to main content

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

Project description

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

What’s new


  • Added a decorator

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


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.


From pip, run:

$ pip install --upgrade django-print-sql

Consider using the --user option.

From the repository, run:

python 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


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]:

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

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

django-print-sql-2018.3.6.tar.gz (3.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page