-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Jay Lee edited this page May 30, 2021
·
19 revisions
Welcome to Decko wiki!
Decko is a decorator-based library designed for the following purposes
- Make the creation of decorators simple and reduce boilerplate
- Change the behavior of existing classes and function with minimal modifications
- Manage the state
- Provide a rich set of pre-made and tested decorators.
Self-contained decorators that can be used without creating a Decko
instance is under development.
Install and update using pip:
pip install -U decko
Uninstall using pip:
pip uninstall decko
Decko's API is divided into two main parts.
decorators.py
: This provides a rich set of pre-built decorators that can be used immediately in your projects.
The main decorator is called deckorator
, a utility decorator for creating decorators. To demonstrate its power,
the code below is a simple timer()
decorator that measures the runtime of a function without using deckorator
.
import time
def timer(func):
"""
An ordinary decorator.
Will be used to check the
performance of decorated function
"""
def inner(*args, **kwargs):
start_time = time.time()
output = func(*args, **kwargs)
elapsed = time.time() - start_time
print(f"Time elapsed: {elapsed}")
return output
return inner
if __name__ == "__main__":
@timer
def create_list(n):
return list(range(n))
create_list(1000000)
Status: This wiki will be updated periodically as new features are added.
Updated on: May 30/05/21