Skip to main content

Django middleware that integrates Server-Timing header

Project description

django-server-timing

CI codecov

Django middleware that exposed collected metrics into HTTP Server Timing header.

This headers is used by browser to display several metrics into the Timing tab of the Network interface. Right now, this header is not supported properlly by all browser

It doesn't effect unsupported browser.

This middleware will send the entire header value since not all browsers supports sending it via HTTP Trailer.

Install

It works on Python >= 3.10 and Django >= 4.2

Install easily via pip or uv

pip install django-server-timing
# or with uv
uv add django-server-timing

# For SQL timing with django-silk integration
pip install django-server-timing[silk]
# or with uv
uv add django-server-timing[silk]

And configure MIDDLEWARES

MIDDLEWARE += ['server_timing.middleware.ServerTiming']

Usage

import time                                                                        
                                                                                     
from django.http import HttpResponse                                               
                                                                                     
from server_timing.middleware import TimedService, timed, timed_wrapper            
                                                                                     
                                                                                     
@timed_wrapper('index', 'Index View')                                              
def index(request):                                                                
    home_service = TimedService('first', 'First service')                          
    home_service.start()                                                           
                                                                                     
    time.sleep(0.3)                                                                
                                                                                     
    home_service.end()                                                             
                                                                                     
    with timed('second', 'Second service'):                                        
        time.sleep(0.5)                                                            
                                                                                     
    return HttpResponse('This page shows a list of most recent posts.')

Server Timing Example

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_server_timing-0.2.0.tar.gz (141.9 kB view details)

Uploaded Source

Built Distribution

django_server_timing-0.2.0-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file django_server_timing-0.2.0.tar.gz.

File metadata

  • Download URL: django_server_timing-0.2.0.tar.gz
  • Upload date:
  • Size: 141.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_server_timing-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5ee804ce900b9ba5808d256ca861fe3d3dd52944f6c7caa41d55a08ec95eaa09
MD5 0c0d040d6835cdc46aede9f10ce95ea5
BLAKE2b-256 226ad8679530d3418132ce46faac254c00910a521239519f8c2720f55db39e85

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_server_timing-0.2.0.tar.gz:

Publisher: ci.yml on vtemian/django-server-timing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_server_timing-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_server_timing-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa0182bf175ad15f23daaa9c0caf7c4114e6089fb17ab5ba1c0001984654c14c
MD5 76306f99f69c27ad09c7d4c2d13da8d9
BLAKE2b-256 b2d331f5dab8d4d1486a00c7586d0d8eb327ae4a366e1e199d5f907c71773556

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_server_timing-0.2.0-py3-none-any.whl:

Publisher: ci.yml on vtemian/django-server-timing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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