DEV Community

Cover image for Lovely Silk
Stefan Alfbo
Stefan Alfbo

Posted on

Lovely Silk

I added a new tool to my toolbox this week, Silk. Which is defined like this in their documentation.

Silk is a live profiling and inspection tool for the Django framework.

As a maintainer of a Django project this is a great tool in many ways.

  • Works seamless with Django REST framework
  • Can give you a good overview on how your endpoints are used
  • See details about HTTP requests/responses
  • Profiling
  • SQL query details
  • Statistics
  • And more...

The tool is added as a regular middleware for a typical Django project, so it's pretty straightforward to add it.

First we need to install the django-silk package.

python -m pip install django-silk
Enter fullscreen mode Exit fullscreen mode

After the package is installed we will need to update our list of middlewares in the setting.py file. The placement in the list can matter, read more about it here.

MIDDLEWARE = [
   ...
   "silk.middleware.SilkyMiddleware",
   ...
Enter fullscreen mode Exit fullscreen mode

We also need to add silk as an app.

INSTALLED_APPS = (
   ...
   "silk",
   ...
)
Enter fullscreen mode Exit fullscreen mode

To be able to use the front-end for Silk we will need to add its path to the urls.py.

urlpatterns += [path("silk/", include("silk.urls", namespace="silk"))]
Enter fullscreen mode Exit fullscreen mode

Since the tool is using the database to store its data we will also need to do a database migration.

python manage.py migrate

# And collect static files from each applications
python manage.py collectstatic

# Start the server
python manage.py runserver
Enter fullscreen mode Exit fullscreen mode

Now you can start to explore all the nice things with Silk. The Silk UI is located at http://localhost:8000/silk.

If you want to do some profiling you will need some more configuration, which also is easy to get started with.

This is really a must have tool if you are doing anything with Django.

Give it a try!

Top comments (0)