Skip to main content

Python Flask Server-Timing Header Extension

Project description

# Flask Server-Timing Header Extension

A Flask extension to easily add the Server-Timing header to allow supported browsers to show backend performance metrics.

From the [Mozilla Developer site](

> The Server-Timing header communicates one or more metrics and descriptions for a given request-response cycle. It is used to surface any backend server timing metrics (e.g. database read/write, CPU time, file system access, etc.) in the developer tools in the user's browser

The Server-Timing specification is a [W3C draft](

## Installation

pip install flask-server-timing

Python versions 2.7 and 3.x are supported with Flask from version 0.10.1.

## Browser Support

Generally all newer, major browsers - excluding IE and Safari - support visualizing the Server-Timing header. For an up-to-date list with specific versions see the [Mozilla Developer]( site

## Usage

from flask import Flask
import time

# Import extension
from from server_timing import Timing

app = Flask(__name__)

# To initialize the extension simply pass the app to it. If the app is in debug
# mode or the force_debug parameter is True an after-request handler will be added
# to write the actual header.
t = Timing(app, force_debug=True)

def examples():
# explicitly calling start and stop before and after - keys need to be identical
t.start('done and done')
t.stop('done and done')

# context manager support to avoid having to call start and stop explicitly
with t.time('context'):

# decorated with name being the key
# decorated without name so the function is the key

def named_decoration():

def unnamed_decoration():

The `example/` directory also contains the following file showing how to time functions in other modules:

import time

# before this file is imported make sure the extension has been initialized with the Flask app
from server_timing import Timing as t

def include():

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

flask-server-timing-0.1.2.tar.gz (3.3 kB view hashes)

Uploaded Source

Supported by

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