{ "info": { "author": "Peinan ZHANG", "author_email": "peinan7@gmail.co.jp", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# swpy: A simple, yet useful stopwatch library for python\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/swpy.svg?logo=python&logoColor=white&style=flat-square)](https://pypi.org/project/swpy/)\n[![PyPI](https://img.shields.io/pypi/v/swpy.svg?style=flat-square)](https://pypi.org/project/swpy/)\n[![CircleCI](https://img.shields.io/circleci/project/github/peinan/swpy.svg?logo=circleci&style=flat-square)](https://circleci.com/gh/peinan/swpy/tree/master)\n[![codecov](https://img.shields.io/codecov/c/gh/peinan/swpy.svg?logo=codecov&style=flat-square)](https://codecov.io/gh/peinan/swpy)\n[![PyPI - License](https://img.shields.io/pypi/l/swpy.svg?color=blue&style=flat-square)](https://github.com/peinan/swpy/blob/master/LICENSE)\n\n## Requirements\n\n- Python 3.6+\n\n## Install\n\nJust use pip to install.\n\n```bash\npip install swpy\n```\n\n## Usage\n\n### Basic Usage\n\nImport `Timer` class from `swpy`, and use `with` statement to capsule the block where you want timing.\n\n```python\nfrom swpy import Timer\nfrom time import sleep\n\nwith Timer():\n sleep(1)\n```\n\nOr use `start()` and `stop()` function to controll the timer.\n\n```python\nt = Timer()\nt.start()\nsleep(1)\nt.stop()\n```\n\nAnd the output will look like below:\n\n```\n[timer-1557406243.3309178] started.\n[timer-1557406243.3309178] finish time: 1.00 sec.\n```\n\n### Features\n\n#### Name the timer\n\nYou can name the timer to make it easy to recognize.\n\n```python\nwith Timer(name='test timer'):\n sleep(1)\n```\n\nNow the timer is renamed to `test timer` !\n\n```\n[test timer] started.\n[test timer] finish time: 1.00 sec.\n```\n\n#### Lap time and Split time\n\nThere are two types to measuring time without stoping: lap time and split time. The figure below may help you to understand the differences.\n\n![split_lap_time](https://github.com/peinan/swpy/blob/master/imgs/split_lap_time.png)\n\nWe prepared `split` and `lap` functions for this kind of usage. The examples are below.\n\n```python\n# measure split time\nwith Timer('timer') as t:\n sleep(1)\n t.split()\n sleep(1)\n t.split()\n sleep(1)\n t.split()\n```\n\n```\n# outptus\n[timer] started.\n[timer] split time: 1.00 sec.\n[timer] split time: 2.01 sec.\n[timer] split time: 3.01 sec.\n[timer] finish time: 3.01 sec.\n```\n\n```python\n# measure lap time\nwith Timer('timer') as t:\n sleep(1)\n t.lap()\n sleep(1)\n t.lap()\n sleep(1)\n t.lap()\n```\n\n```\n# outputs\n[timer] started.\n[timer] lap time: 1.00 sec.\n[timer] lap time: 1.01 sec.\n[timer] lap time: 1.00 sec.\n[timer] finish time: 3.01 sec.\n```\n\nAnd you can name your lap/split time in the case of measuring several tasks in a single run as below.\n\n```python\nwith Timer('task timer') as t:\n task1()\n t.lap('task1')\n task2()\n t.lap('task2')\n```\n\n```\n# outputs\n[task timer] started.\n[task timer] [task1] lap time: 3.69 sec.\n[task timer] [task2] lap time: 4.21 sec.\n[task timer] finish time: 7.91 sec.\n```\n\n#### Use your own logger\n\nYou can use your own logger instead of the default `print`.\n\n```python\nfrom logzero import logger\nimport logging\n\nwith Timer(name='test timer', logger=logger, level=logging.DEBUG):\n sleep(1)\n```\n\nIt will output using logger.\n\n```\n[D 190510 14:41:59 swpy:15] [test timer] started.\n[D 190510 14:42:00 swpy:15] [test timer] finish time: 1.01 sec.\n```\n\n#### Define your own callback\n\nSometimes, we want to do something after the job has done like notifying the result to slack, executing the next process and so on. Callback feature will help you to do those.\n\n```python\n# define a slack notification function\nimport requests, json\ndef send_slack(msg):\n requests.post(SLACK_URL, json.dumps({'text': msg}))\n\n# just specify the callback argument\nwith Timer(name='experiment-1', callback=send_slack):\n sleep(1)\n```\n\n## License\n\n[MIT](https://github.com/peinan/swpy/blob/master/LICENSE)\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/peinan/swpy", "keywords": "stopwatch,timer", "license": "MIT", "maintainer": "Peinan ZHANG", "maintainer_email": "peinan7@gmail.co.jp", "name": "swpy", "package_url": "https://pypi.org/project/swpy/", "platform": "", "project_url": "https://pypi.org/project/swpy/", "project_urls": { "Homepage": "https://github.com/peinan/swpy", "Repository": "https://github.com/peinan/swpy" }, "release_url": "https://pypi.org/project/swpy/0.1.2/", "requires_dist": null, "requires_python": ">=3.6,<4.0", "summary": "A simple, yet useful stopwatch library.", "version": "0.1.2" }, "last_serial": 5612428, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "d90eb289b6c71f34d1049ad27aeb1588", "sha256": "27450b823ab088b02060c3dad5b583b6d333fab34dc3c127cfdf99940825d722" }, "downloads": -1, "filename": "swpy-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d90eb289b6c71f34d1049ad27aeb1588", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 3437, "upload_time": "2019-05-10T08:13:47", "url": "https://files.pythonhosted.org/packages/5e/96/985d73bbbadd3d4c42337ac68065f2b45d3587f0622f696e8dca92fb4d49/swpy-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "320a7b2238791bd8072ef2da6fc9e511", "sha256": "762fde787b92f3e8c5cbd4cd02442603b919ca53a1b7eebe6ef2d207843d140d" }, "downloads": -1, "filename": "swpy-0.1.1.tar.gz", "has_sig": false, "md5_digest": "320a7b2238791bd8072ef2da6fc9e511", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 3317, "upload_time": "2019-05-10T08:13:48", "url": "https://files.pythonhosted.org/packages/d3/cd/94fc919762ee1afd4e8baae8fda2e739e90ef9173f68f5e17aa24bff294f/swpy-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "ef182cb527d597d828716cf573318533", "sha256": "72a6262a7f6853f17791351cb9e772a9cfb298253e1586f68f26922c9f08fdf4" }, "downloads": -1, "filename": "swpy-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "ef182cb527d597d828716cf573318533", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 4160, "upload_time": "2019-07-31T09:30:40", "url": "https://files.pythonhosted.org/packages/92/f3/ef4cbc730d84c9fd1b5a6dca411cf2493675dbe201af93455f75b00461cc/swpy-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b9649228528ceb93c5cc019d82b3e8e", "sha256": "e9c62941386e826247c384a95bf6a38f9a95449e742cb5357ffe1c2afe5d51aa" }, "downloads": -1, "filename": "swpy-0.1.2.tar.gz", "has_sig": false, "md5_digest": "8b9649228528ceb93c5cc019d82b3e8e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 4283, "upload_time": "2019-07-31T09:30:42", "url": "https://files.pythonhosted.org/packages/fe/f5/e88b8dfb5fd5f126634339bde1af74f397b26f1826063f0576a52010e5d7/swpy-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ef182cb527d597d828716cf573318533", "sha256": "72a6262a7f6853f17791351cb9e772a9cfb298253e1586f68f26922c9f08fdf4" }, "downloads": -1, "filename": "swpy-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "ef182cb527d597d828716cf573318533", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 4160, "upload_time": "2019-07-31T09:30:40", "url": "https://files.pythonhosted.org/packages/92/f3/ef4cbc730d84c9fd1b5a6dca411cf2493675dbe201af93455f75b00461cc/swpy-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b9649228528ceb93c5cc019d82b3e8e", "sha256": "e9c62941386e826247c384a95bf6a38f9a95449e742cb5357ffe1c2afe5d51aa" }, "downloads": -1, "filename": "swpy-0.1.2.tar.gz", "has_sig": false, "md5_digest": "8b9649228528ceb93c5cc019d82b3e8e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 4283, "upload_time": "2019-07-31T09:30:42", "url": "https://files.pythonhosted.org/packages/fe/f5/e88b8dfb5fd5f126634339bde1af74f397b26f1826063f0576a52010e5d7/swpy-0.1.2.tar.gz" } ] }