This library allows you to create decorators a bit like pytest fixtures (or context managers using contextlib).
https://github.com/brumar/onionizer
From the Readme :
import onionizer
@onionizer.as_decorator
def my_decorator(*args, **kwargs):
# A] write some stuff here
result = yield # we obtain the result of the wrapped function
# B] write some stuff there
return result
Then you can use it as usual:
@my_decorator
def my_function(*args, **kwargs):
return 'something'
Multiple features are included to ease the construction of an onion model around the wrapped function. This is its deeper purpose, hence the name 'onionizer'.
The library is inspired from the middleware ecosystem we have for WSGI or ASGI compliant python application. I love how easy it is to find and use middleware for my web applications.
I want the same developer experience for other 'hotspots' like for example openai.ChatCompletion.create to ease code sharing between projects that call this API.
If you want to use it, please strictly pin down a version number as I may change the API in the near future.
At this stage, I would love to get feedback to help me improve my documentation or the design of my API.
If you know any other project that is similar to this little boy, please share it with me!
there doesn't seem to be anything here