Skip to main content

A debugging tool for Django applications which works for all HTTP requests including AJAX. Using this, you can profile Django views. It shows you all SQL, Memcache queries with proper stacktrace happening in app while serving a request, with the help of 'Scooby profiler' chrome extension.

Project description

django-scooby-profiler

This is a developer tool package to debug Django applications. The aim of this package is more or less same as of Django debug toolbar, but I made it because of these shortcomings of django-debug-toolbar package:

  1. You can not debug AJAX requests with django-debug-toolbar.
  2. If you have a big Django project, the django-debug-toolbar makes web pages more slower because it injects its own html by rendering which takes time.

With django-scooby-profiler:

  1. You can debug AJAX requests as well.
  2. It comes with a chrome extension named "Scooby profiler", so rendering happens at front-end only.
  3. You have to switch on debugging in chrome extension, only then backend will collect profiled data for all queries. This way, the overhead caused by debugging is not always ON by default.

Here's how the issues are mitigated in django-scooby-profiler. All the profiled data collected is dumped to a backend (E.g. Redis) where the data resides temporarily. The chrome extension collects those data and renders it to you for different HTTP requests.

Plugins supported

Currently plugins for these type of queries are supported by this package:

  1. SQL: Debug SQL queries happening inside the app, while serving a request. It shows all SQL queries with proper stacktrace. You can group together similar queries at front-end, so that you would know what queries you can optimize. This is what generally happens in case of for loops.

  2. Memcache: It shows different operations on memcache with stacktraces.

  3. Scooby logs: Instead of debugging/printing on console, you can log things directly to extension. Do it by putting following anywhere in you code where you want to log.

import scooby
scooby.log("foo", "bar")
# or
scooby.log()         # It works without giving any argument too.
  1. Python cProfile: If you want to use raw python profiler on your Django view, you don't need to add any extra code for that. This plugin does the job for you.

If you don't find a plugin here which you think should be here, you are most welcome to contribute it to this package.

Installation

# Use pip in case of Python 2
pip3 install django-scooby-profiler 

Backend configuration

  1. Add 'scooby' to INSTALLED_APPS setting.
INSTALLED_APPS = [
  ...,
  'scooby',
]
  1. Add this middeware to MIDDLEWARE/MIDDLEWARE_CLASSES setting:
MIDDLEWARE = [
  'scooby.middleware.ScoobyMiddleware',
  ...,
]
  1. Add following manadatory settings:
  • SCOOBY_SECRET_KEY (type: string)

You can generate a secret key by

>>> import os
>>> import binascii
>>> print(binascii.hexlify(os.urandom(24)))
0ccd512f8c3493797a23557c32db38e7d51ed74f14fa758
  • SCOOBY_REDIS_BACKEND_CONFIG (type: dict, connection params required for redis connection)

This is not required if SCOOBY_BACKEND is set as some other backend. The setting would look like

SCOOBY_REDIS_BACKEND_CONFIG = {
  'host': 'localhost',
  'port': 6379
}
  1. Add scooby base url to your project's urlconf by

with Django 2.x.x:

urlpatterns = [
    ...,
    path('scooby/', include('scooby.urls')),
]

with lower versions of Django:

urlpatterns = [
    ...,
    url(r'^scooby/', include('scooby.urls')),
]

Other optional Settings

  • SCOOBY_DEBUG (type: boolean, default: DEBUG) Whether to debug or not regarding this package.

  • SCOOBY_BACKEND (type: string, path to the class which acts as backend, default: 'scooby.backends.RedisBackend') You can specify your own backend if you don't want to use Redis. You need to create a class similar to RedisBackend defined in scooby/backends.py

Install chrome extension

Install the chrome extension from https://chrome.google.com/webstore/detail/scooby-profiler/kicgfdanpohconjegfkojbpceodecjad

Open the developer tools in your browser, you will see a section named "Scooby". It will ask for the secret key, which you need to put as same you have put in the backend. Reload your page, you will start seeing HTTP requests with profiled data for all supported plugins.

LICENCE

MIT

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-scooby-profiler-2.0.3.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_scooby_profiler-2.0.3-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file django-scooby-profiler-2.0.3.tar.gz.

File metadata

  • Download URL: django-scooby-profiler-2.0.3.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for django-scooby-profiler-2.0.3.tar.gz
Algorithm Hash digest
SHA256 8efebe9537e3ab04659b6d4f5a9a1bc4f043d0ebea69319288bdb365f1cf5006
MD5 1fa6dea8479ecda8799fb18b81771d7a
BLAKE2b-256 f0348e79f3b8e09d30e927a6c69b20069ac521e888a3f59793111122ff68d006

See more details on using hashes here.

File details

Details for the file django_scooby_profiler-2.0.3-py3-none-any.whl.

File metadata

  • Download URL: django_scooby_profiler-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for django_scooby_profiler-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1b5c7f8bca5ae6339caba8a4881966bf9650cc64953c10ba41031e2514cdbefd
MD5 4da3f92ffda49b7555d38eaddfe4d05f
BLAKE2b-256 4313c6e9a1d96e1f9312f6c82ff79312d75fcc72656ba2caa43bfb0ec751e1de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page