Skip to main content

Pretty Wrappers

PyPI Python 3.8, 3.9, 3.10 License

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

Metadata

Release files for PrettyWrappers 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PrettyWrappers 0.0.2
File Size Uploaded
PrettyWrappers-0.0.2.tar.gz 3.0 kB Details

Release files / PrettyWrappers-0.0.2.tar.gz

Download URL PrettyWrappers-0.0.2.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ddadef90556a693096175efad4e6df528e08aa2b6196f980367f54021fea7249
BLAKE2b-256 checksum
How to use checksums
d2ccc6e437bfc54cb20f7faa60905d5fa6983dc74d1586e103e3f42009a3c98e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page