A simple, yet useful stopwatch library.
Project description
swpy: A simple, yet useful stopwatch library for python
Requirements
- Python 3.6+
Install
$ pip install swpy
Usage
>>> from swpy import Timer
>>> import time
# the simplest use
>>> with Timer():
... time.sleep(1)
[timer-1557406243.3309178] started.
[timer-1557406243.3309178] finish time: 1.00 sec.
# name the timer for visibility
>>> with Timer(name='test timer'):
... time.sleep(1)
[test timer] started.
[test timer] finish time: 1.00 sec.
# use your own logger
>>> from logzero import logger
>>> import logging
>>> with Timer(name='test timer', logger=logger, level=logging.DEBUG):
... time.sleep(1)
[D 190510 14:41:59 swpy:15] [test timer] started.
[D 190510 14:42:00 swpy:15] [test timer] finish time: 1.01 sec.
# process the timer result with your own function with callback
## define a slack notification function
>>> import requests, json
>>> def send_slack(msg):
... requests.post(SLACK_URL, json.dumps({'text': msg}))
## just specify the callback argument
>>> with Timer(name='experiment-1', logger=logger, level=logging.DEBUG, callback=send_slack):
... time.sleep(1)
[D 190510 14:48:17 swpy:15] [experiment-1] started.
[D 190510 14:48:18 swpy:15] [experiment-1] finish time: 1.01 sec.
License
MIT
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
swpy-0.1.1.tar.gz
(3.3 kB
view hashes)
Built Distribution
swpy-0.1.1-py3-none-any.whl
(3.4 kB
view hashes)