sag-py-execution-time-decorator


Namesag-py-execution-time-decorator JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/SamhammerAG/sag_py_execution_time_decorator
SummaryA decorator for methods to log the execution time (sync and async)
upload_time2024-05-06 12:22:08
maintainerNone
docs_urlNone
authorSamhammer AG
requires_python>=3.8
licenseMIT
keywords logging execution time
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sag_py_execution_time_decorator
[![Maintainability][codeclimate-image]][codeclimate-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]

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:
```python
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 BlackConnect
* Install pycharm plugin Mypy
* Configure the python interpreter/venv
* pip install requirements-dev.txt
* pip install black[d]
* Ctl+Alt+S => Check Tools => BlackConnect => Trigger when saving changed files
* Ctl+Alt+S => Check Tools => BlackConnect => Trigger on code reformat
* Ctl+Alt+S => Click Tools => BlackConnect => "Load from pyproject.yaml" (ensure line length is 120)
* Ctl+Alt+S => Click Tools => BlackConnect => Configure path to the blackd.exe at the "local instance" config (e.g. C:\Python310\Scripts\blackd.exe)
* Ctl+Alt+S => Click Tools => Actions on save => Reformat code
* 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

[codeclimate-image]:https://api.codeclimate.com/v1/badges/fa4312e587c8185db077/maintainability
[codeclimate-url]:https://codeclimate.com/github/SamhammerAG/sag_py_execution_time_decorator/maintainability
[coveralls-image]:https://coveralls.io/repos/github/SamhammerAG/sag_py_execution_time_decorator/badge.svg?branch=master
[coveralls-url]:https://coveralls.io/github/SamhammerAG/sag_py_execution_time_decorator?branch=master
[snyk-image]:https://snyk.io/test/github/SamhammerAG/sag_py_execution_time_decorator/badge.svg
[snyk-url]:https://snyk.io/test/github/SamhammerAG/sag_py_execution_time_decorator

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SamhammerAG/sag_py_execution_time_decorator",
    "name": "sag-py-execution-time-decorator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "logging, execution time",
    "author": "Samhammer AG",
    "author_email": "support@samhammer.de",
    "download_url": "https://files.pythonhosted.org/packages/dd/e7/59a271c558ac7c265e7b783aa8c67c5bb335a7b7f6ca7658d09b6f642912/sag_py_execution_time_decorator-1.0.2.tar.gz",
    "platform": null,
    "description": "# sag_py_execution_time_decorator\n[![Maintainability][codeclimate-image]][codeclimate-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n\nA decorator for methods to log the execution time (sync and async)\n\n## What it does\n- Logs the execution time in milliseconds\n\nSample log entry:\n```\ndecorated_sync_method took 1000 ms.\n```\n\nThe entry contains \"function_name\" and \"execution_time\" as extra data.\n\n## Installation\npip install sag-py-execution-time-decorator\n\n## How to use\nDecorate your methods like that:\n```python\nfrom sag_py_execution_time_decorator.execution_time_decorator import log_execution_time\n\n@log_execution_time()\ndef decorated_sync_method(param: str) -> str:\n    time.sleep(SLEEP_TIME_MS / 1000)\n    return f\"test: {param}\"\n\n\n@log_execution_time(log_level=logging.ERROR, log_params=(\"param\",))\nasync def decorated_async_method(param: str) -> str:\n    await asyncio.sleep(SLEEP_TIME_MS / 1000)\n    return f\"test: {param}\"\n\n```\n\nOptional arguments:\n| Argument    | Description                                                          | Default                  |\n|-------------|----------------------------------------------------------------------|--------------------------|\n| log_level   | The log level integar. Use logging.* constants                       | logging.INFO             |\n| logger_name | The name of the logger that is internally used for logging.getLogger | execution_time_decorator |\n| log_params  | A tuple of parameter names to be logged with their values in 'extra' | ()                       |\n\n## How to start developing\n\n### With vscode\n\nJust install vscode with dev containers extension. All required extensions and configurations are prepared automatically.\n\n### With pycharm\n\n* Install latest pycharm\n* Install pycharm plugin BlackConnect\n* Install pycharm plugin Mypy\n* Configure the python interpreter/venv\n* pip install requirements-dev.txt\n* pip install black[d]\n* Ctl+Alt+S => Check Tools => BlackConnect => Trigger when saving changed files\n* Ctl+Alt+S => Check Tools => BlackConnect => Trigger on code reformat\n* Ctl+Alt+S => Click Tools => BlackConnect => \"Load from pyproject.yaml\" (ensure line length is 120)\n* Ctl+Alt+S => Click Tools => BlackConnect => Configure path to the blackd.exe at the \"local instance\" config (e.g. C:\\Python310\\Scripts\\blackd.exe)\n* Ctl+Alt+S => Click Tools => Actions on save => Reformat code\n* Restart pycharm\n\n## How to publish\n* Update the version in setup.py and commit your change\n* Create a tag with the same version number\n* Let github do the rest\n\n## How to test\n\nTo avoid publishing to pypi unnecessarily you can do as follows\n\n* Tag your branch however you like\n* 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>`\n* Rebuild/redeploy your project\n\n[codeclimate-image]:https://api.codeclimate.com/v1/badges/fa4312e587c8185db077/maintainability\n[codeclimate-url]:https://codeclimate.com/github/SamhammerAG/sag_py_execution_time_decorator/maintainability\n[coveralls-image]:https://coveralls.io/repos/github/SamhammerAG/sag_py_execution_time_decorator/badge.svg?branch=master\n[coveralls-url]:https://coveralls.io/github/SamhammerAG/sag_py_execution_time_decorator?branch=master\n[snyk-image]:https://snyk.io/test/github/SamhammerAG/sag_py_execution_time_decorator/badge.svg\n[snyk-url]:https://snyk.io/test/github/SamhammerAG/sag_py_execution_time_decorator\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A decorator for methods to log the execution time (sync and async)",
    "version": "1.0.2",
    "project_urls": {
        "Bug Reports": "https://github.com/SamhammerAG/sag_py_execution_time_decorator/issues",
        "Documentation": "https://github.com/SamhammerAG/sag_py_execution_time_decorator",
        "Homepage": "https://github.com/SamhammerAG/sag_py_execution_time_decorator",
        "Source": "https://github.com/SamhammerAG/sag_py_execution_time_decorator"
    },
    "split_keywords": [
        "logging",
        " execution time"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a53a8f5a5b406d6452ac9fd9095bf29cffb0478cef53c3832d1c2b2f023b69ff",
                "md5": "8861eb338136c7ca84fb4337755294ad",
                "sha256": "4e254828bc10f9dd1eee62c84e3acee0b084c70774c996ac21b7dd4c7b2e82c8"
            },
            "downloads": -1,
            "filename": "sag_py_execution_time_decorator-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8861eb338136c7ca84fb4337755294ad",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5675,
            "upload_time": "2024-05-06T12:22:06",
            "upload_time_iso_8601": "2024-05-06T12:22:06.631857Z",
            "url": "https://files.pythonhosted.org/packages/a5/3a/8f5a5b406d6452ac9fd9095bf29cffb0478cef53c3832d1c2b2f023b69ff/sag_py_execution_time_decorator-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dde759a271c558ac7c265e7b783aa8c67c5bb335a7b7f6ca7658d09b6f642912",
                "md5": "b76aaf23acdd2b866cf485119b759b51",
                "sha256": "32cdbace0b9d3c2d78ccc881d83dc5822f3ebc73b9578e4f8d03c96c16b06465"
            },
            "downloads": -1,
            "filename": "sag_py_execution_time_decorator-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b76aaf23acdd2b866cf485119b759b51",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 5927,
            "upload_time": "2024-05-06T12:22:08",
            "upload_time_iso_8601": "2024-05-06T12:22:08.553522Z",
            "url": "https://files.pythonhosted.org/packages/dd/e7/59a271c558ac7c265e7b783aa8c67c5bb335a7b7f6ca7658d09b6f642912/sag_py_execution_time_decorator-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-06 12:22:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SamhammerAG",
    "github_project": "sag_py_execution_time_decorator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "sag-py-execution-time-decorator"
}
        
Elapsed time: 0.25089s