Wrap a function to add behavior—logging, timing, auth—without touching its code.
A wrapper you put around a function so that something happens every time it runs — timing it, retrying it, logging it — without editing the function itself.
Every framework you'll touch is built on them, and 'explain a decorator' is a standard screening question.
A decorator is a function that takes another function, wraps it in a new function that runs extra behavior before or after the call, and returns that wrapper. The @decorator syntax is just sugar for f = decorator(f). functools.wraps copies the original's metadata so introspection still works.
A decorator is a higher-order function: it receives a function and returns a replacement that adds behavior around it—logging, timing, auth, caching, retries—without editing the original. The @ syntax simply rebinds the name to the decorated version. I always add functools.wraps so the wrapper keeps the original name, docstring, and signature.
25. Decorators [Python 3 Programming Tutorials] — codebasics, 9:07