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.

```python
import scooby
scooby.log("foo", "bar")
# or
scooby.log() # It works without giving any argument too.
```

4) **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

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

## Backend configuration

1) Add 'scooby' to `INSTALLED_APPS` setting.
```python
INSTALLED_APPS = [
...,
'scooby',
]
```

2) Add this middeware to `MIDDLEWARE`/`MIDDLEWARE_CLASSES` setting:
```python
MIDDLEWARE = [
'scooby.middleware.ScoobyMiddleware',
...,
]
```

3) 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

```python
SCOOBY_REDIS_BACKEND_CONFIG = {
'host': 'localhost',
'port': 6379
}
```

4) 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.7.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

django_scooby_profiler-2.0.7-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-scooby-profiler-2.0.7.tar.gz
  • Upload date:
  • Size: 9.4 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.7.tar.gz
Algorithm Hash digest
SHA256 5226082988a2f9dd2df7b6193fd0c6ca5281277f2ee17f695152926f8d76a718
MD5 5dc79122d3e5cc76ed9684fb98536f22
BLAKE2b-256 f41f21daef8d2c547781e888159fa874419e1fe6fb3d92e9e22f976aef0ea081

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_scooby_profiler-2.0.7-py3-none-any.whl
  • Upload date:
  • Size: 18.2 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 715eb065c4402eadc6256b2d94e042d423eb916998b9b11434e9a45d02d496fe
MD5 2281a1389bea3159c7ff3e814ae8c192
BLAKE2b-256 68784c4f98c59bc54dab18e5ac7131656adc79635ab7da021b4a768598c50f95

See more details on using hashes here.

Supported by

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