awesome-python-decorator

Decorator library

A curated collection of Python decorator resources and examples

A curated list of awesome python decorator resources.

GitHub

740 stars
26 watching
67 forks
last commit: over 2 years ago
Linked from 1 awesome list


Awesome Python Decorator / You don't know decorator

PEP 0318 -- Decorators for Functions and Methods
PEP 3129 -- Class Decorators
Python Wiki - PythonDecoratorsThis page largely documents the history of the process of adding decorators to Python
Python Wiki - PythonDecoratorLibraryThis page is meant to be a central repository of decorator code pieces. Lots of decorator examples, really cool!

Awesome Python Decorator / Built-in python decorator

@abc.abstractmethodA decorator indicating abstract methods
@abc.abstractpropertyA subclass of the built-in , indicating an abstract property
@asyncio.coroutineDecorator to mark generator-based coroutines. New in version 3.4
@atexit.registerRegister func as a function to be executed at termination
@classmethodReturn a class method for function
@contextlib.contextmanagerDefine a factory function for with statement context managers, without needing to create a class or separate and methods
@functools.cached_propertyTransform a method of a class into a property whose value is computed once and then cached as a normal attribute for the life of the instance
@functools.lru_cacheDecorator to wrap a function with a memoizing callable that saves up to the maxsize most recent calls. It can save time when an expensive or I/O bound function is periodically called with the same arguments. New in python 3.2
@functools.singledispatchTransforms a function into a single-dispatch generic function. New in python 3.4
@functools.total_orderingGiven a class defining one or more rich comparison ordering methods, this class decorator supplies the rest
@functools.wrapsThis is a convenience function for invoking update_wrapper() as a function decorator when defining a wrapper function
@propertyReturn a property attribute
@staticmethodReturn a static method for function
@types.coroutineThis function transforms a generator function into a coroutine function which returns a generator-based coroutine. New in python 3.5
@unittest.mock.patchActs as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the target is patched with a new object. When the function/with statement exits the patch is undone. New in python 3.3
@unittest.mock.patch.dictPatch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test. New in python 3.3
@unittest.mock.patch.multiplePerform multiple patches in a single call. New in python 3.3
@unittest.mock.patch.objectPatch the named member (attribute) on an object (target) with a mock object. New in python 3.3

Awesome Python Decorator / Python decorator in the wild

cached-property704almost 2 years agoA decorator for caching properties in classes
cachetools2,370almost 2 years agoThis module provides various memoizing collections and decorators, including variants of the Python 3 Standard Library @lru_cache function decorator
celery25,062almost 2 years agoCelery is a distributed task queue, it uses decorator to create tasks
click15,881almost 2 years agoClick is a Python package for creating beautiful command line interfaces, based on declaring commands through decorators. You can also check out the library which shares a similar idea with click
deco1,573almost 5 years agoA simplified parallel computing model for Python. DECO automatically parallelizes Python programs, and requires minimal modifications to existing serial programs
decorator853almost 2 years agoThis is your best option if you want to preserve the signature of decorated functions in a consistent way across Python releases
deprecated310almost 2 years agoUse decorator to deprecate old python classes, functions or methods. Decorators can also be used to add Sphinx directives
fasteners254over 2 years agoProvides useful locks and decorators to lock/unlock around functions and methods
flask68,340almost 2 years agoFlask is a micro web framework in python, which uses decorators to route the URL, register error handler, register processor and so on
flask-login3,589almost 2 years agoFlask-Login provides user session management for Flask. For example, it use the decorator to protect some views that need the user to be logged in
GB2260.py126over 6 years agoThis project is used to look up Chinese administrative divisions. It uses decorators to write Python 2.x and 3.x compatible code
marshmallow7,069almost 2 years agoA lightweight library for converting complex objects to and from simple Python datatypes. It use decorators to register schema pre-processing and post-processing methods
me-api15over 7 years agoAn extensible, personal API with custom integrations. It uses a decorator to make sure there is an access_token in the configuration file before sending the API request and reject another authentication if there is already an access_token
numbaNumba gives you the power to speed up your applications with high performance functions written directly in Python. It uses to decorate array-oriented and math-heavy Python code can be just-in-time compiled to native machine instructions, similar in performance to C, C++ and Fortran, without having to switch languages or Python interpreters
lettuce1,272over 5 years agoLettuce is a BDD tool for python. It uses and to decorate functions and classes so they become new step definitions
profilehooks328almost 2 years agoPython decorators for profiling/tracing/timing a single function
pypi-cli167over 10 years agopypi-cli is a command-line interface to the Python Package Index. It use decorator to makes a property lazy-evaluated
py-spin183almost 4 years agopy-spin is a terminal spinner package for python. Yes, it does use a decorator to register a function that needs to take a long time to finish, as well as showing a spinner while it's processing!
python-goto1,279over 5 years agoA function decorator that rewrites the bytecode, enabling goto in python
showme189over 3 years agoShowMe is a simple set of extremely useful function decorators for Python. It allows you to view trace information, execution time, cputime, and function documentation
tenacity6,870almost 2 years agoSimplifies the task of adding retry behavior to just about anything. It originates from a fork of
timeout-decorator631over 2 years agoTimeout decorator for Python which uses a decorator to limit the execution time of the given function
Tomorrow1,460over 6 years agoTomorrow use decorator to do the magic that let you write asynchronous code with ease
wrapt2,078almost 2 years agoA Python module for decorators, wrappers and monkey patching

Backlinks from these awesome lists:

More related projects: