Tutorials: Introduction to Decorators: Power Up Your Python Code

Thursday - April 20th, 2023 1:30 p.m.-5 p.m. in

Presented by:

Experience Level:

Some experience


You can use decorators in your Python code to change the behavior of one or several functions. Many popular libraries are based on decorators. For example, you can use decorators to register functions as web endpoints, mark functions for JIT compilation, or profile your functions.

Using decorators makes your code simpler and more readable. However, to unlock the full capability of decorators, you should also be comfortable writing your own. In this tutorial, you'll learn how decorators work under the hood, and you'll get plenty of practice writing your own decorators.

You'll be introduced to necessary background information about how functions are first-class objects in Python and how you can define inner functions. You'll learn how to unwrap the @decorator syntactic sugar and how to write solid decorators that you can use in your code.

Being comfortable with using and creating decorators will make you a more efficient Python programmer.