</>CodexBash
All articles
Python and JavaScript

Python decorators

How the @ syntax wraps a function: functions as values, writing a decorator step by step, functools.wraps, decorators with arguments, timing, logging, retries and caching, class decorators, and the decorators you already use.

CodexBash, , 4 min read

The @ symbol above a Python function looks like magic the first time: @app.route("/"), @property, @lru_cache. It is actually a small, simple idea, a function that wraps another function, built on the fact that in Python functions are ordinary values. Once you see how it works, you can read any decorator and write your own for timing, logging, retries and more.

Sign in to read the rest

The whole 4 minute article is free with an account, along with every problem, lesson and tutorial. No card.