A Flask extension to easily add the Server-Timing header to allow supported browsers to show backend performance metrics.
From the [Mozilla Developer site](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing):
> 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](https://www.w3.org/TR/server-timing)
## 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](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing#Browser_compatibility) site
## Usage
```python
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)
@app.route("/examples")
def examples():
# explicitly calling start and stop before and after - keys need to be identical
t.start('done and done')
time.sleep(0.3)
t.stop('done and done')
# context manager support to avoid having to call start and stop explicitly
with t.time('context'):
time.sleep(0.2)
# decorated with name being the key
named_decoration()
# decorated without name so the function is the key
unnamed_decoration()
@t.timer(name='named')
def named_decoration():
time.sleep(0.4)
@t.timer
def unnamed_decoration():
time.sleep(0.5)
app.run(host="0.0.0.0",port=8080)
```
The `example/` directory also contains the following file showing how to time functions in other modules:
```python
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
@t.timer
def include():
time.sleep(0.1)
```
Metadata
Release files for flask-server-timing 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask-server-timing-0.1.2.tar.gz | 3.3 kB | Without provenance | Details for flask-server-timing-0.1.2.tar.gz |
Release files / flask-server-timing-0.1.2.tar.gz
| Download URL | flask-server-timing-0.1.2.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e448683912089ada8d3af78c260687e1b5bfd0381430f8b52f7ff2a931166efa
|
|
BLAKE2b-256 checksum How to use checksums |
6c21f14bcfdc7a9554949d2a87a73ce5c1b7802cf359f5fca5ef33f07669eaf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15
|
Security for flask-server-timing 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.