Zeitdieb
Zeitdieb allows you to profile the time each line of your code takes.
pip install zeitdieb
Manual usage
with StopWatch(additional, callables) as sw:
your()
code()
print(sw)
Alternatively, without using the context manager:
sw = StopWatch(additional, callables)
sw.start()
your()
code()
sw.finish()
print(sw)
Formatting
While you can just print the StopWatch object, you can also customize the output by using f-strings:
print(f"{sw:3b:0.3,0.1}")
The format spec looks like this: [width][flags]:[threshold][,threshold].
widthspecifies the width of the time column (e.g.4for an output like2.01)flagsare single-letter flags influencing the output:benables barplot mode: Instead of a numeric time output, a vertical barplot will be printed
thresholds specify where to start marking times as critical/warnings (red/yellow). The thresholds must be ordered (highest to lowest).
Integrations
Zeitdieb can optionally be intregrated with Pyramid, Flask, or FastAPI. After
you've done so, you can trigger tracing with the special header X-Zeitdieb.
Pyramid
Put this somewhere in your Pyramid settings:
zeitdieb.format = 20b
pyramid.tweens =
...
zeitdieb.pyramid
Flask
For Flask or flask-based frameworks, adjust your create_app() function:
def create_app():
...
my_flask_app.config["ZEITDIEB_FORMAT"] = "7b:0.5"
zeitdieb.flask(my_flask_app)
FastAPI
FastAPI can be configured by calling zeitdieb.fastapi() inside of create_app():
class Settings(...):
...
zeitdieb_format: Optional[str] = "6b"
def create_app(...):
...
zeitdieb.fastapi(app, settings)
Settings client headers
To trigger the tracing of functions, you need to set an X-Zeitdieb header:
curl
$ curl https://.../ -H 'X-Zeitdieb: path.to.module:callable,path.to.othermodule:callable`
jsonrpclib
jsonrpclib.ServerProxy(host, headers={"X-Zeitdieb": "path.to.module:callable,path.to.othermodule:callable"})
Acknowledgements
This project was created as a result of a learning day @ solute.
Metadata
Release files for zeitdieb 0.3.1
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 | |
|---|---|---|---|---|
| zeitdieb-0.3.1.tar.gz | 5.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zeitdieb-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.2 kB
Release files / zeitdieb-0.3.1.tar.gz
| Download URL | zeitdieb-0.3.1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
359ec82a0c76b10227ef361872aa4c992e06f9a4dca9e5071be62bd4ebd95392
|
|
BLAKE2b-256 checksum How to use checksums |
4a2a391f0ad8442ec6c46f09704cf1e8ca112d374340f063ff95f629c8caca90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.10.0 Darwin/23.5.0
|
Release files / zeitdieb-0.3.1-py3-none-any.whl
| Download URL | zeitdieb-0.3.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db96a4392814a566eb861a0a07242e5d12414182cab580d1d98ac3f2c6918860
|
|
BLAKE2b-256 checksum How to use checksums |
d0d14299cb5e956a37362fc89abc807a09d0d098f1dafb50deade34b8d35be2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.10.0 Darwin/23.5.0
|
Security for zeitdieb 0.3.1
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.