{ "info": { "author": "Real Python", "author_email": "info@realpython.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: MacOS", "Operating System :: Microsoft", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Topic :: Education", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: System :: Monitoring", "Typing :: Typed" ], "description": "# `codetiming` - A flexible, customizable timer for your Python code\n\n[![Latest version](https://img.shields.io/pypi/v/codetiming.svg)](https://pypi.org/project/codetiming/)\n[![Python versions](https://img.shields.io/pypi/pyversions/codetiming.svg)](https://pypi.org/project/codetiming/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n[![CircleCI](https://circleci.com/gh/realpython/codetiming.svg?style=shield)](https://circleci.com/gh/realpython/codetiming)\n\nInstall `codetiming` from PyPI:\n\n```\n$ python -m pip install codetiming\n```\n\nThe source code is [available at GitHub](https://github.com/realpython/codetiming).\n\n\n## Basic Usage\n\nYou can use `codetiming.Timer` in several different ways:\n\n1. As a **class**:\n\n ```python\n t = Timer(name=\"class\")\n t.start()\n # Do something\n t.stop()\n ```\n\n2. As a **context manager**:\n\n ```python\n with Timer(name=\"context manager\"):\n # Do something\n ```\n\n3. As a **decorator**:\n\n ```python\n @Timer(name=\"decorator\")\n def stuff():\n # Do something\n ```\n\n\n## Arguments\n\n`Timer` accepts the following arguments when it's created, all are optional:\n\n- **`name`:** An optional name for your timer\n- **`text`:** The text shown when your timer ends. It should contain a `{}` placeholder that will be filled by the elapsed time in seconds (default: `\"Elapsed time: {:.4f} seconds\"`)\n- **`logger`:** A function/callable that takes a string argument, and will report the elapsed time when the logger is stopped (default: `print()`)\n\nYou can turn off explicit reporting of the elapsed time by setting `logger=None`.\n\nWhen using `Timer` as a class, you can capture the elapsed time when calling `.stop()`:\n\n```python\nelapsed_time = t.stop()\n```\n\nNamed timers are made available in the class dictionary `Timer.timers`. The elapsed time will accumulate if the same name or same timer is used several times. Consider the following example:\n\n```python\n>>> import logging\n>>> from codetiming import Timer\n\n>>> t = Timer(\"example\", text=\"Time spent: {:.2f}\", logger=logging.warning)\n\n>>> t.start()\n>>> t.stop()\nWARNING:root:Time spent: 3.58\n3.5836678670002584\n\n>>> with t:\n... _ = list(range(100000000))\n... \nWARNING:root:Time spent: 1.73\n\n>>> Timer.timers\n{'example': 5.312697440000193}\n```\n\nThe example shows how you can redirect the timer output to the logging module. Note that the elapsed time spent in the two different uses of `t` has been accumulated in `Timer.timers`.\n\n\n## Acknowledgements\n\n`codetiming` is based on a similar module originally developed for the [Midgard Geodesy library](https://kartverket.github.io/midgard/) at the [Norwegian Mapping Authority](https://www.kartverket.no/en/).", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://realpython.com/", "keywords": "timer class contextmanager decorator", "license": "", "maintainer": "", "maintainer_email": "", "name": "codetiming", "package_url": "https://pypi.org/project/codetiming/", "platform": "", "project_url": "https://pypi.org/project/codetiming/", "project_urls": { "Homepage": "https://realpython.com/", "Source Code": "https://github.com/realpython/codetiming" }, "release_url": "https://pypi.org/project/codetiming/0.1.2/", "requires_dist": [ "dataclasses; python_version < '3.7'", "black; extra == \"dev\"", "bump2version; extra == \"dev\"", "flake8; extra == \"dev\"", "flit; extra == \"dev\"", "mypy; extra == \"dev\"", "pytest; extra == \"test\"", "pytest-cov; extra == \"test\"", "tox; extra == \"test\"" ], "requires_python": ">=3.6", "summary": "A flexible, customizable timer for your Python code", "version": "0.1.2" }, "last_serial": 5621185, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "51049918cf6e583076b02c3ca9d75576", "sha256": "99be55f9b6dfa94721cd80e1efae0c84542312304323fbb2545a949f5ec1d791" }, "downloads": -1, "filename": "codetiming-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "51049918cf6e583076b02c3ca9d75576", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5826, "upload_time": "2019-07-29T20:46:05", "url": "https://files.pythonhosted.org/packages/3f/af/1dc7400ff3f31f98ae4094e28336452294d5d4b0e1fe0e78523152e91a62/codetiming-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "72d7ff671cc6405a3e1a044459d145ce", "sha256": "2b6bbb58d27bbab23683784d2be491e2177d48914f297451712af64d8eafda5f" }, "downloads": -1, "filename": "codetiming-0.1.0.tar.gz", "has_sig": false, "md5_digest": "72d7ff671cc6405a3e1a044459d145ce", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5373, "upload_time": "2019-07-29T20:46:08", "url": "https://files.pythonhosted.org/packages/56/f5/262a5092e27563f3ccdc89cf4253a4d7f32bc80abe5bc748f47a8fbd6ade/codetiming-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "8cc890dfca610880548861b3a117788e", "sha256": "bdb740dd0dd0f83c407d6fcbab5c42fbc83667203a62563ac1119ef261f139b3" }, "downloads": -1, "filename": "codetiming-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "8cc890dfca610880548861b3a117788e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5981, "upload_time": "2019-07-30T10:30:08", "url": "https://files.pythonhosted.org/packages/b2/5c/9984218d7a8a95cfaca2eccc27195b88db6816c4197c3662ab1533ef9584/codetiming-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "49ae9eed3eab72e5e03adda77595bb40", "sha256": "a0321d85cdca5ba294ce9d96bfb36344fe53aab786edc7946a2a5ee0e0525aa3" }, "downloads": -1, "filename": "codetiming-0.1.1.tar.gz", "has_sig": false, "md5_digest": "49ae9eed3eab72e5e03adda77595bb40", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5506, "upload_time": "2019-07-30T10:30:11", "url": "https://files.pythonhosted.org/packages/29/67/12b747cfd752a7a3af2f9f45781662e312efe9159e838a02994a07bf562f/codetiming-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "8af6ae85c08ff52775f7088f4a18b6f2", "sha256": "093c6be8a786b47ce52bbdbcc917faa666bd868cb19c52655dbd3b644b0ae3ba" }, "downloads": -1, "filename": "codetiming-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "8af6ae85c08ff52775f7088f4a18b6f2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 6554, "upload_time": "2019-08-01T22:59:43", "url": "https://files.pythonhosted.org/packages/88/f0/0717a8b370955934f6204ab9ab4a5c3bc0b870870be50dc647fc66ace887/codetiming-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7f4024b3ad44d8a3fb0938bb43693552", "sha256": "2bec6b70613dabde539bb62427e5115289984e6924a41ecec12a6ce6e8d17a17" }, "downloads": -1, "filename": "codetiming-0.1.2.tar.gz", "has_sig": false, "md5_digest": "7f4024b3ad44d8a3fb0938bb43693552", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 6148, "upload_time": "2019-08-01T22:59:45", "url": "https://files.pythonhosted.org/packages/4f/3b/cee7d80554282928c83e887c694c36562596812985fe663cfa725486b5d8/codetiming-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8af6ae85c08ff52775f7088f4a18b6f2", "sha256": "093c6be8a786b47ce52bbdbcc917faa666bd868cb19c52655dbd3b644b0ae3ba" }, "downloads": -1, "filename": "codetiming-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "8af6ae85c08ff52775f7088f4a18b6f2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 6554, "upload_time": "2019-08-01T22:59:43", "url": "https://files.pythonhosted.org/packages/88/f0/0717a8b370955934f6204ab9ab4a5c3bc0b870870be50dc647fc66ace887/codetiming-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7f4024b3ad44d8a3fb0938bb43693552", "sha256": "2bec6b70613dabde539bb62427e5115289984e6924a41ecec12a6ce6e8d17a17" }, "downloads": -1, "filename": "codetiming-0.1.2.tar.gz", "has_sig": false, "md5_digest": "7f4024b3ad44d8a3fb0938bb43693552", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 6148, "upload_time": "2019-08-01T22:59:45", "url": "https://files.pythonhosted.org/packages/4f/3b/cee7d80554282928c83e887c694c36562596812985fe663cfa725486b5d8/codetiming-0.1.2.tar.gz" } ] }