Use cases for decorators in Python

  • classmethod
  • staticmethod
  • pytest

  • dataclasses
  • Logging calls with parameters.
  • Logging elapsed time of calls.
  • Access control in Django or other web frameworks. (e.g. login required)
  • Memoization (caching)
  • Retry
  • Function timeout
  • Locking for thread safety
  • Decorator Library