Skip to main content

Decorators for Developers

Project description

wrapworks

Introduction

The wrapworks package provides decorators and helper functions for various functionalities such as timing function execution, handling exceptions, and automatic function retries.

Installation

You can install wrapworks using pip:

pip install wrapworks

Features

  • timeit: Decorator to print the execution duration of a function.
  • tryexcept: Decorator to add a try-except block around a function.
  • retry: Decorator to automatically retry a function.

Usage

Timing Function Execution

from wrapworks import timeit

@timeit()
def my_function():
    pass

Handling Exceptions

from wrapworks import tryexcept

@tryexcept(default_return=None)
def another_function():
    pass

Automatic Function Retries

from wrapworks import retry

@retry(max_retries=3, delay=1, default_return=None)
def some_function():
    pass

Easy printing of exceptions

from wrapworks import eprint

def some_function():
    try:
        raise ValueError()
    except Exception as e:
        eprint(e , some_function)

Add current directory to system path and load environment variables

from wrapworks import cwdtoenv
cwdtoenv()

Customizing Output

You can customize the output behavior of the wrapworks decorators by specifying a level parameter when using them.

Additionally, you can further control the display of print statements based on the WRAPWORKSLEVEL environment variable as follows:

  • If the level parameter in a decorator is higher than the WRAPWORKSLEVEL environment variable, the print statement from that decorator will be displayed.
  • Set WRAPWORKSLEVEL to a specific level (e.g., 1, 2, 3, etc.) to control which decorators' print statements are shown based on their respective levels.
  • Print statements from decorators with a level lower than the WRAPWORKSLEVEL will be suppressed, providing a cleaner output in the console or log files.

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

wrapworks-1.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wrapworks-1.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file wrapworks-1.1.0.tar.gz.

File metadata

  • Download URL: wrapworks-1.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for wrapworks-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ac1a18d1beb723a4745b2e13b75281d0fe34ac1a32a448f63a5eab5e967db2bf
MD5 1b55d2bb04b3b622b06e55c9b8a29e59
BLAKE2b-256 fc3aee989d07e0bf60c01580164a06c11cccbb1dd161d59dd23da49230f725c1

See more details on using hashes here.

File details

Details for the file wrapworks-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: wrapworks-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for wrapworks-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76af6795388b0c3868f61ed1e0026ae75fe9da7369378b26e4a7a4eaf1f7e310
MD5 d7af6f2cc859c8b5dce8d4b55871e8a1
BLAKE2b-256 f816e412491121619125572ac624187b2d2219be8fc5f5f07850e3e710b5c7c8

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