Penguin: a customizable stopwatch decorator
Project description
🐧 penguin-py 🐧
Penguin is a lightweight, customizable stopwatch ⏱ decorator that helps you determine how long it takes for your functions to run. It supports both synchronous and asynchronous functions.
Source code
The source code of this package lives here: https://github.com/espitiaandres/penguin
Installation
With Command Line
To install penguin-py
with the command line, run this command:
pip install penguin-py
.
With a requirements.txt
file
To install penguin-py
using a requirements.txt
file, add this line to your requirements.txt
file.
penguin-py==0.3.12
Usage
Synchronous Functions
For synchronous functions, use the @penguin()
decorator.
✅ To run with default kwargs:
from penguin_py import penguin
@penguin()
def foo(test1, test2=None):
# Note: this function can be anything!
for i in range(10000000):
pass
return "test", True
test = foo("", test2="")
✅ To run with user specified kwargs:
@penguin(
verbose=True,
show_args=True,
show_return=True,
foreground='cyan',
background='yellow',
)
def foo(test1, test2=None):
for i in range(10000000):
pass
return "test", True
test = foo("", test2="")
Note: For a more detailed list of all kwargs and their defaults, visit this section: List of kwargs
❌ Since penguin
is a decorator that takes in kwargs, do not call it without the brackets ()
.
from penguin_py import penguin
@penguin
def foo(test1, test2=None):
# Note: this function can be anything!
for i in range(10000000):
pass
return "test", True
test = test_func("", test2=":")
If you do this, you'll get a TypeError
relating to arguments.
Asynchronous Functions
For asynchronous functions, use the @penguin_async()
decorator.
✅ To run with default kwargs:
from penguin_py import penguin
@penguin_async()
def foo(test1, test2=None):
# Note: this function can be anything!
for i in range(10000000):
pass
return "test", True
test = foo("", test2="")
This will output the following to your logger:
✅ To run with user specified kwargs:
@penguin(
verbose=True,
show_args=True,
show_return=True,
foreground='cyan',
background='yellow',
)
def foo(test1, test2=None):
for i in range(10000000):
pass
return "test", True
test = foo("", test2="")
This will output the following to your logger:
List of kwargs
verbose
: WhenTrue
, it shows all logs that are described by the other kwargs. WhenFalse
, each kwarg would determine if that specific log is shown - default:False
show_args
: WhenTrue
, it shows the function's signature, with the*args
and**kwargs
being passed in.- default:
False
- default:
show_return
: WhenTrue
, it shows the function's return value(s).- default:
False
- default:
foreground
: When chosen from this list,["red", "yellow", "green", "blue", "magenta", "cyan", "grey"]
, it colour the logger output text the chosen colour.- default:
"grey"
- default:
background
: When chosen from this list,["red", "yellow", "green", "blue", "magenta", "cyan", "grey", "black", "white"]
, it colour the logger output background the chosen colour.- default:
"black"
- default:
Documentation
Documentation of penguin-py
can be found here: https://github.com/espitiaandres/penguin/blob/master/README.md
Bugs/Requests
If you find any bugs or have any suggestions to penguin-py
, submit them in the issues tab in the Github repo. This can be found here: https://github.com/espitiaandres/penguin/issues
License
Distributed under the terms of the MIT license, penguin-py
is free and open source software.
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
File details
Details for the file penguin_py-0.3.12.tar.gz
.
File metadata
- Download URL: penguin_py-0.3.12.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e866c78f18ef081e12a0bc60ac791401fbeb6c8cc5b00139f88bad57373f35 |
|
MD5 | e7bc8a71ffabe1e58c0bee1a4b91380f |
|
BLAKE2b-256 | e69ec5646f2d7e2f7429b361b6b97a48824e1334c09427ecb5a346b11f40627b |
File details
Details for the file penguin_py-0.3.12-py3-none-any.whl
.
File metadata
- Download URL: penguin_py-0.3.12-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8344fcfb496ecd6461601cc49c798d73aa66aeca7ef43f82fafa84e0cda54af1 |
|
MD5 | 9c5db28db35389533cbf38fc3eef42bb |
|
BLAKE2b-256 | cd8d561cc2c48e2ea44e106ec59f1d488ec12325449faaeca810cf1ecd6e5b7e |