Skip to main content

a zoo for decorators

Project description

deczoo

A zoo for decorators

There are many great decorators out there that we use everyday. Why don't collect few of them?

I found myself implementing over and over in different projects. The hope is to gather them here and use this codebase.

Alpha Notice

This package is really new and there are edge cases that probably doesn't cover (yet).

Installation

You can install the library using pip:

python -m pip install deczoo

Getting started

We have a documentation page that explains how each feature works.

Each function here is a decorator with a specific objective in mind.

from deczoo import log

@log # equivalent to @log(log_time=True, log_args=True, log_error=True, logging_fn=print)
def my_add_function(a, b, *args):
    """Adds all arguments together"""
    return sum([a, b, *args])

_ = my_add_function(1, 2, 3, 4)
# my_add_function args=(a=1, b=2, args=(3, 4)) time=0:00:00.000062

 _ = my_add_function(1, "a", 2)
# my_add_function args=(a=1, b=a, args=(2,)) time=0:00:00.000064 Failed with error: unsupported
# operand type(s) for +: 'int' and 'str'

Features

The library implements few (function) decorators:

  • call_counter: Counts how many times a function has been called
  • catch: Wraps a function in a try-except block
  • check_args: Checks that function arguments satisfy given rules
  • chime_on_end: Notify with chime sound on function end
  • dump_result: Saves function result in a pickle file
  • log: Tracks function time taken, arguments and errors
  • timer: Tracks function time taken
  • memory_limit: Sets a memory limit for a function
  • retry: Wraps a function with a retry block
  • timeout: Sets a time limit to a function to run

Feedbacks

Any feedback, improvement/enhancement or issue is welcome in the issue page of the repo.

Contributing

Make sure to check the issue list beforehand.

To get started locally, you can clone the repo and quickly get started using the Makefile:

git clone git@github.com:FBruzzesi/deczoo.git
cd deczoo
make init-develop

Licence

This repository has a MIT Licence

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

deczoo-0.1.0.tar.gz (7.8 kB view hashes)

Uploaded Source

Built Distribution

deczoo-0.1.0-py2.py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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