No project description provided
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.
Documentation: https://fbruzzesi.github.io/deczoo
Source Code: https://github.com/fbruzzesi/deczoo
Alpha Notice
This codebase is experimental and is working for my use cases. It is very probable that there are cases not covered and for which it breaks (badly). If you find them, please feel free to open an issue in the issue page of the repo.
Installation
deczoo is published as a Python package on pypi, and it can be installed with pip, ideally by using a virtual environment (suggested option), or directly from source using git, or with a local clone:
- pip:
python -m pip install deczoo
- source/git:
python -m pip install git+https://github.com/FBruzzesi/deczoo.git
- local clone:
git clone https://github.com/FBruzzesi/deczoo.git cd deczoo python -m pip install .
Getting started
The idea is kind of simple: each function in the library is a (function) 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 the following 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 functionnotify_on_end
: notifies you when a function finished with a custom notifierretry
: Wraps a function with a retry blocktimeout
: Sets a time limit to a function to run
Examples
Please refer to the api page to see a basic example for each decorator.
Contributing
Please read the Contributing guidelines in the documentation site.
License
The project 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.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 432e3e58f8062e1a9f5d346a4fb7bd7d24537fc6a1ccc3657b97a337360b2c2a |
|
MD5 | edd9c8156360797741e61c2306f6b7be |
|
BLAKE2b-256 | 259cd5b1e2d44a47d7193eb23e5436d013fc536f21cec908e6f5a896d58b0a3a |