Guide to: Learning Python Decorators

Introducing Guide to: Learning Python Decorators
Guide To: Learning Python Decorators is a complete guide to the theory and implementation of decorators. Decorators are pretty common in Python. While not strictly necessary, they can reduce code size while enabling control of function input, invocation and output. Many explanations of decorators are brief and leave the reader somewhat confused. This book is an attempt to remedy that. It is based off of popular tutorials given at PyCon and Python user groups. Without fail, attendees mention that “decorators now make sense”. Not only do they understand them, but they can write them as well.
Learn Decorators
corators are used all over the place in modern Python code. They are used for:
- Caching expensive calculations
- Retrying a function that might fail
- Redirecting
sys.stdoutto capture what a function prints to it - Logging the amount of time spent in a function
- Timing out a function call
- Access control
- More …
Guide to: Learning Python Decorators The book is available on Amazon and the Kindle lending library if you have a Prime membership for a discounted price of $3.99. Join the hundreds of others who have learned these tips from the author through conference tutorials and sessions now presented in book form.
Packed with Useful Hints and Tips
This books covers:
- Programming paradigms in Python
- First-class functions
- Function scope
- Nested functions
- Function parameters
- Closures
- Free variables
- The splat operator
- Closures
- Decoratoring with functions
- Decorating with classes
- Decorator templates
- Parameterized decorators
- Well-behaved decorators
- Multiple decorators
- Common uses for decorators
You’ll learn the best practices without wasting time searching or picking up advice here and there. I’ve collected all the gems I’ve gleaned over years of writing and teaching Python for you.
A No Nonsense Guide to Decorators in Python

Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.
Praise for the Book and Related Tutorials
#1 Book for Python Programming
#1 Book for Python Programming
“guide to python decorators is crisp, concise, clear”
“I’m fairly certain I understand how decorators work now. Thanks to @__mharrison__’s presentation. Time to try out the exercises.”
“So I have a much clearer understanding of Closures in general, and func decorators in Python. Thanks @__mharrison__ !”
Loved @__mharrison__ talk at #scale10x on Python decorators - learned a lot!
@__mharrison__ Your #python decorator session was a top tier talk at #scale10x. Thx for presenting. Let me know when your book is available.
Just got a great refresher on Py decorators from @__mharrison__, years after being shown the light by @RanjitJhala #SCaLE10X
Understanding decorators, *args, **kwargs etc. made driving down to #SCALE10x worth it. Thankyou @__mharrison__
Wow, @__mharrison__ is *killing* it with his Python functions and decorators talk. Lots of good info. #SCALE10x
I’m fairly new to python and your talk was *extremely* informative and interesting. I can imagine all sorts of cool use cases for decorators and am imagining even perhaps a standard library of decorators!
About the Book
Guide to: Learning Python Decorators distills years of experience coding and teaching Python and presents it in a easily digestable form. It is full of examples to illustrate the skills needed to read and write decorators in Python. Also included are callouts to indicate common gotchas as well as best practices. Those looking to understand how decorators work and how to write them will be able to come up to speed much faster with this book than working on their own.
Guide to: Learning Python Decorators is the book I wanted when I was learning decorators in Python. I have taught Python to hundreds over the years at conferences, and user groups, and I’m combining the most pertinent and useful information for you.
About the Author

Matt Harrison has over 10 years Python experience across the domains of search, build management and testing, business intelligence and storage.
He has presented and taught tutorials at conferences such as SCALE, PyCON and OSCON as well as local user groups. In addition he has been a private tutor teaching programming to teenagers as well as retired folk. The structure of this book is based off of his first hand experience teaching Python to many individuals.
Matt occasionally tweets useful Python related information at __mharrison__ and Matt blogs at hairysun.com