Skip to main content

Build Status

Handy Decorators


This is a set of handy decorators which one can use for their day-to-day life coding.

Installation Method

Install it via pip

pip install handy-decorators

Description

The set of decorators contain some daily needed decorators for being used in our day to day coding life. This has following set of decorators.

trycatch

This decorator surounds your function with a try-except block and if your code/function raises an exception, it's caught by this decorator and reported by logging.

>>> from decorators import trycatch
>>> @trycatch
... def func():
...     print(0/0) # Division by 0 must raise exception
...
>>> func()
Exception occurred: [integer division or modulo by zero]
>>>

timer

This decorator will calculate a time required in seconds by your function for execution.

>>> from decorators import timer
>>> @timer
... def a():
...     import time
...     print('Hi')
...     time.sleep(1)
...
>>> a()
Hi
Time taken by the function is [1.00103902817] sec
>>>

singleton

This decorator is for making your class singleton.
The features given by this decorator are:

  • If instances of same class are created with same args and kwargs, decorator will return previously existing instance
  • If instances of same class are created with different args and kwargs, decorator will create a different one for you and store the newly created instance
>>> from decorators import singleton
>>>
>>> @singleton
... class A:
...     def __init__(self, *args, **kwargs):
...         pass
...
>>>
>>> a = A(name='Siddhesh')
>>> b = A(name='Siddhesh', lname='Sathe')
>>> c = A(name='Siddhesh', lname='Sathe')
>>> a is b  # has to be different
False
>>> b is c  # has to be same
True
>>>

Please create an issue if more decorators are needed.

Release files for handy-decorators 0.0.7

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

Built distribution (wheel)

Table of built distributions (wheels) for handy-decorators 0.0.7
File Interpreter ABI Platform
handy_decorators-0.0.7-py2-none-any.whl Python 2 none any Details

Release files / handy_decorators-0.0.7-py2-none-any.whl

Download URL handy_decorators-0.0.7-py2-none-any.whl
Size 15.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
953deea0a2836d2944436b2b2e6d9e4d980d9b37fc1a75b0fc95cbc8a018aa27
BLAKE2b-256 checksum
How to use checksums
bcf899c760e4f1c6226add1b358a740fe1b1d5bb5fe488dd601acb1446a3bda2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.12

Release history Release notifications | RSS feed

This release

0.0.7 This release

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