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 calledcatch
: Wraps a function in a try-except blockcheck_args
: Checks that function arguments satisfy given ruleschime_on_end
: Notify with chime sound on function enddump_result
: Saves function result in a pickle filelog
: Tracks function time taken, arguments and errorstimer
: Tracks function time takenmemory_limit
: Sets a memory limit for a functionretry
: Wraps a function with a retry blocktimeout
: 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for deczoo-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a9f1d9456dd9269e220d45351c31d6505a6b01c369766f2bc0d81c43ae0f30f |
|
MD5 | 8ad6fae9d20bab085cf8f841d7722181 |
|
BLAKE2b-256 | 13a3fc2ac45e6222443caa2eaf6894152d729392f8966ad2b72e5a872b261228 |