https://github.com/notmatthancock/festoon
A collection of useful Python decorators
https://github.com/notmatthancock/festoon
Last synced: 2 months ago
JSON representation
A collection of useful Python decorators
- Host: GitHub
- URL: https://github.com/notmatthancock/festoon
- Owner: notmatthancock
- License: mit
- Created: 2021-12-04T23:44:08.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-21T03:44:58.000Z (over 3 years ago)
- Last Synced: 2025-01-28T23:48:58.631Z (4 months ago)
- Language: Python
- Size: 3.16 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `festoon`
`festoon` ([read the full docs here](https://notmatthancock.github.io/festoon/)) is a collection of useful Python decorators for common tasks.
Here's an example that retries a function on failures:
```python
from festoon import retry@retry(schedule=[1, 2, 8, 32], catch=ConnectionError)
def flaky_function():
...
```
Here's a concrete logging example:
```python
from festoon import logit@logit
def func(x, y=2, z="something else"):
return x+yif __name__ == "__main__":
import logging
logging.basicConfg(level=logging.INFO)
func(1)
# INFO.__main__: CALL func(x=1, y=2, z="something else")
# INFO.__main__: DONE func->3
```
Notice that implicit default parameters are logged when using the default call formatter function.Here is an example to inject variables into a docstring:
```python
from festoon import docfillLOW = 0.5
HIGH = 0.75
ANIMAL_CHOICES = ("dog", "cat", "ostrich")@docfill(LOW, HIGH, animals=ANIMAL_CHOICES)
def func(threshold: float, animal: str):
"""Do a thingArgs:
threshold: a value between {0:.2f} and {1:.2f}
animal: valid options are {animals}
"""
...if __name__ == "__main__":
help(func)
# Help on function func in module __main__:
#
# func(threshold: float, animal: str)
# Do a thing
#
# Args:
# threshold: a value between 0.50 and 0.75
# animal: valid options are ('dog', 'cat', 'ostrich')
```