PrettyWrappers 0.0.2

Creator: bradpython12

Last updated:

Add to Cart

Description:

PrettyWrappers 0.0.2

Pretty Wrappers

Pretty Wrappers - this module is a Python client library that adds useful for development decorators
Installation
Install the current version with PyPI:
pip install PrettyWrappers

Usage
You can import each module individually
from PrettyWrappers import timer, logging, ...

Or if you need to use several modules at once, you can import all library as pw
import PrettyWrappers

pw = PrettyWrappers

Example

Timer - Execution time counting decorator. Print the result to the console.
from PrettyWrappers import timer


@timer
def request(url):
import requests

res = requests.get(url)
return res


request('http://google.com')

Output:
[*] Execution time: 0.577 sec


If you need to get the execution time as a variable, for subsequent actions with it, you can use naked_timer
Naked Timer - Execution time counting decorator. But it returns dictionary.
{'execution time': float, 'result': any}
from PrettyWrappers import naked_timer


@naked_timer
def request(url):
import requests

res = requests.get(url)
return res


print(request('http://google.com'))

Output:
{'execution_time': 0.589, 'result': <Response [200]>}

We can extract the execution time of the dictionary
result = request('http://google.com')

execution_time = result['execution_time']

print(execution_time)
print(type(execution_time))

Output:
0.578
<class 'float'>


Pause - Pause-creating decorator.
@pause(seconds: int or float)
from PrettyWrappers import timer, pause


@timer
@pause(1)
def request(url):
import requests

res = requests.get(url)
return res


request('http://google.com')

Output without "pause" :
[*] Execution time: 0.405 sec

Output with "pause" :
[*] Execution time: 1.405 sec


Counter - Decorator counting the count of calls function. Print the result to the console.
from PrettyWrappers import counter


@counter
def request(url):
import requests

res = requests.get(url)
return res


request('http://google.com')
request('http://pypi.org')

Output:
[*] Function [request] was called: 1x
[*] Function [request] was called: 2x


Logging - Logging decorator.
(Just print information about the called function. Real logging will be added later).
from PrettyWrappers import logging


@logging
def request(url):
import requests

res = requests.get(url)
return res


request('http://google.com')

Output:
[*] Function: request
(*) args: ('http://google.com',)
(*) kwargs: {}


Contributing
Bug reports and/or pull requests are welcome.
Also you can write to me
Instagram : @nikitun.kun
License
The module is available as open source under the terms of the Apache License, Version 2.0

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.