Practical decorators

How decorators work, and examples of how to use them in your programs

Reuven Lerner

Compiler and Interpreters Data Structures Programming Python Skills Python general

See in schedule

Decorators are one of Python's most powerful features. But even if you understand what they do, it's not always obvious what you can do with them. Sure, from a practical perspective, they let you remove repeated code from your callables. And semantically, they let you think at a higher level of abstraction, applying the same treatment to functions and classes.

But what can you actually do with them? For many Python developers I've encountered, decorators sometimes appear to be a solution looking for a problem.

In this talk, I'll show you some practical uses for decorators, and how you can use them to make your code more readable and maintainable, while also providing more semantic power. Moreover, you'll see examples of things would be hard to do without decorators. I hope that after this talk, you'll have a good sense of how to use decorators in your own Python projects.

Type: Talk (30 mins); Python level: Advanced; Domain level: Beginner

Reuven Lerner

Lerner Consulting

Reuven teaches Python, data science, and Git to companies around the world. He also offers many online courses, including "Weekly Python Exercise," a community-based way to improve your Python fluency over time. Reuven writes two free, weekly newsletters — "Better developers" (about Python development, with more than 11,000 subscribers) and "Trainer weekly" (for technical trainers who want to improve their skills). Reuven is a senior columnist at Linux Journal and co-hosts the Freelancers Show podcast. More information about Reuven, his courses, and writing is at .