A decorator for methods to log the execution time (sync and async)
Project description
sag_py_execution_time_decorator
A decorator for methods to log the execution time (sync and async)
What it does
- Logs the execution time in milliseconds
Sample log entry:
decorated_sync_method took 1000 ms.
The entry contains "function_name" and "execution_time" as extra data.
Installation
pip install sag-py-execution-time-decorator
How to use
Decorate your methods like that:
from sag_py_execution_time_decorator.execution_time_decorator import log_execution_time
@log_execution_time()
def decorated_sync_method(param: str) -> str:
time.sleep(SLEEP_TIME_MS / 1000)
return f"test: {param}"
@log_execution_time(log_level=logging.ERROR, log_params=("param",))
async def decorated_async_method(param: str) -> str:
await asyncio.sleep(SLEEP_TIME_MS / 1000)
return f"test: {param}"
Optional arguments:
| Argument | Description | Default |
|---|---|---|
| log_level | The log level integar. Use logging.* constants | logging.INFO |
| logger_name | The name of the logger that is internally used for logging.getLogger | execution_time_decorator |
| log_params | A tuple of parameter names to be logged with their values in 'extra' | () |
How to start developing
With vscode
Just install vscode with dev containers extension. All required extensions and configurations are prepared automatically.
With pycharm
- Install latest pycharm
- Install pycharm plugin Mypy
- Configure the python interpreter/venv
- pip install requirements-dev.txt
- Restart pycharm
How to publish
- Update the version in setup.py and commit your change
- Create a tag with the same version number
- Let github do the rest
How to test
To avoid publishing to pypi unnecessarily you can do as follows
- Tag your branch however you like
- Use the chosen tag in the requirements.txt-file of the project you want to test this library in, eg.
sag_py_execution_time_decorator==<your tag> - Rebuild/redeploy your project
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sag_py_execution_time_decorator-2.1.4.tar.gz.
File metadata
- Download URL: sag_py_execution_time_decorator-2.1.4.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd47f29fc696863beae2cc235f15d45f6859717cff6f274b8625b3a1fbae83ec
|
|
| MD5 |
04f7a0b35b8b32944a9475f553704fba
|
|
| BLAKE2b-256 |
9b69b2df8c76b46ea718bab9348956f53a9578a53e3f6dbe2008d60c5eccb390
|
File details
Details for the file sag_py_execution_time_decorator-2.1.4-py3-none-any.whl.
File metadata
- Download URL: sag_py_execution_time_decorator-2.1.4-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5d04cf5927c1852932e675e791de65ff377cd83b2d6cdcd208d12b4dbe182ed
|
|
| MD5 |
be2a90fa0ce3bc0da7b0ba3fb6ce8377
|
|
| BLAKE2b-256 |
81126eb22a9ca73a1cb1030a3cb56274a9e037aefff0f89f62f36c37d9ad5ffd
|