Skip to main content

Python module that adds useful for development decorators

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PrettyWrappers-0.0.2.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file PrettyWrappers-0.0.2.tar.gz.

File metadata

  • Download URL: PrettyWrappers-0.0.2.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for PrettyWrappers-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ddadef90556a693096175efad4e6df528e08aa2b6196f980367f54021fea7249
MD5 73763adf1be0ad56ccf96f28d9da7615
BLAKE2b-256 d2ccc6e437bfc54cb20f7faa60905d5fa6983dc74d1586e103e3f42009a3c98e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page