
Practical Python Decorator Uses & Avoiding datetime Pitfalls
02/16/24 • 57 min
1 Listener
What are real-life examples of using Python decorators? How can you harness their power in your code? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder’s Weekly articles and projects.
We discuss a recent article series that digs into Python decorators. The first two articles discuss the basics of constructing decorators. The third part describes how popular Python libraries use decorators with call interception, function registration, and enriching the behavior of a function.
Christopher shares a piece about the common pitfalls of working with the Pythondatetime library. The article considers how current third-party libraries don’t address most of these quirks and offers a potential solution with a new library.
We also share several other articles and projects from the Python community, including a couple of news items, a discussion about the popularity of the Rust language, handling unset values in FastAPI with Pydantic, working with Python’s mini-language for formatting strings, mocking Django queryset functions, and a modern replacement for the Requests library.
This week’s episode is brought to you by Sentry.
Course Spotlight: Python Decorators 101
In this course on Python decorators, you’ll learn what they are and how to create and use them. Decorators provide a simple syntax for calling higher-order functions in Python. By definition, a decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it.
Topics:
- 00:00:00 – Introduction
- 00:02:53 – Django security releases issued: 5.0.2, 4.2.10, and 3.2.24
- 00:03:10 – Python 3.12.2 and 3.11.8 are now available
- 00:03:21 – Introducing PSF Grants Program Office Hours
- 00:04:19 – Python’s Format Mini-Language for Tidy Strings
- 00:12:22 – Ten Python datetime Pitfalls
- 00:18:34 – Sponsor: Sentry
- 00:19:37 – Real Life Use of Decorators
- 00:29:18 – Handling Unset Values in FastAPI With Pydantic
- 00:35:43 – Video Course Spotlight
- 00:37:06 – The Python Rust-Aissance
- 00:50:19 – django-mock-queries: Mock Django Queryset Functions
- 00:53:09 – niquests: Requests but Multiplexed
- 00:55:55 – Thanks and goodbye
News:
- Django security releases issued: 5.0.2, 4.2.10, and 3.2.24
- Python 3.12.2 and 3.11.8 are now available
- Introducing PSF Grants Program Office Hours
Show Links:
- Python’s Format Mini-Language for Tidy Strings – In this tutorial, you’ll learn about Python’s format mini-language. See how to use it for creating working format specifiers and build nicely formatted strings and messages in your code.
- Ten Python datetime Pitfalls – It’s no secret that the Python datetime library has its quirks. Not only are there probably more than you think, but third-party libraries don’t address most of them! Arie created a new library to explore what a better datetime library could look like.
- Real Life Use of Decorators – Part 3 in a series on how Python decorators are used. This part covers real-life use cases including call interception, function registration, and behavioral enrichment.
- Handling Unset Values in FastAPI With Pydantic – When using the HTTP PATCH method only those fields that got changed are updated. Pydantic sets fields not given as arguments as None so there is no way to distinguish between an explicit None value and an unset field. This post explains how you process this scenario.
Discussion:
- The Python Rust-Aissance – Companies like Polars are showing how with Rust, Python developers now have a better, smoother path towards building high-performance libraries.
- Rye: A Python Developer Experience Vision Continued
- PyO3: Rust bindings for the Python interpreter
- Rust in Linux: Where we are...
What are real-life examples of using Python decorators? How can you harness their power in your code? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder’s Weekly articles and projects.
We discuss a recent article series that digs into Python decorators. The first two articles discuss the basics of constructing decorators. The third part describes how popular Python libraries use decorators with call interception, function registration, and enriching the behavior of a function.
Christopher shares a piece about the common pitfalls of working with the Pythondatetime library. The article considers how current third-party libraries don’t address most of these quirks and offers a potential solution with a new library.
We also share several other articles and projects from the Python community, including a couple of news items, a discussion about the popularity of the Rust language, handling unset values in FastAPI with Pydantic, working with Python’s mini-language for formatting strings, mocking Django queryset functions, and a modern replacement for the Requests library.
This week’s episode is brought to you by Sentry.
Course Spotlight: Python Decorators 101
In this course on Python decorators, you’ll learn what they are and how to create and use them. Decorators provide a simple syntax for calling higher-order functions in Python. By definition, a decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it.
Topics:
- 00:00:00 – Introduction
- 00:02:53 – Django security releases issued: 5.0.2, 4.2.10, and 3.2.24
- 00:03:10 – Python 3.12.2 and 3.11.8 are now available
- 00:03:21 – Introducing PSF Grants Program Office Hours
- 00:04:19 – Python’s Format Mini-Language for Tidy Strings
- 00:12:22 – Ten Python datetime Pitfalls
- 00:18:34 – Sponsor: Sentry
- 00:19:37 – Real Life Use of Decorators
- 00:29:18 – Handling Unset Values in FastAPI With Pydantic
- 00:35:43 – Video Course Spotlight
- 00:37:06 – The Python Rust-Aissance
- 00:50:19 – django-mock-queries: Mock Django Queryset Functions
- 00:53:09 – niquests: Requests but Multiplexed
- 00:55:55 – Thanks and goodbye
News:
- Django security releases issued: 5.0.2, 4.2.10, and 3.2.24
- Python 3.12.2 and 3.11.8 are now available
- Introducing PSF Grants Program Office Hours
Show Links:
- Python’s Format Mini-Language for Tidy Strings – In this tutorial, you’ll learn about Python’s format mini-language. See how to use it for creating working format specifiers and build nicely formatted strings and messages in your code.
- Ten Python datetime Pitfalls – It’s no secret that the Python datetime library has its quirks. Not only are there probably more than you think, but third-party libraries don’t address most of them! Arie created a new library to explore what a better datetime library could look like.
- Real Life Use of Decorators – Part 3 in a series on how Python decorators are used. This part covers real-life use cases including call interception, function registration, and behavioral enrichment.
- Handling Unset Values in FastAPI With Pydantic – When using the HTTP PATCH method only those fields that got changed are updated. Pydantic sets fields not given as arguments as None so there is no way to distinguish between an explicit None value and an unset field. This post explains how you process this scenario.
Discussion:
- The Python Rust-Aissance – Companies like Polars are showing how with Rust, Python developers now have a better, smoother path towards building high-performance libraries.
- Rye: A Python Developer Experience Vision Continued
- PyO3: Rust bindings for the Python interpreter
- Rust in Linux: Where we are...
Previous Episode

Focusing on Data Science & Less on Engineering and Dependencies
How do you manage the dependencies of a large-scale data science project? How do you migrate that project from a laptop to cloud infrastructure or utilize GPUs and multiple instances in parallel? This week on the show, Savin Goyal returns to discuss the updates to the open-source framework Metaflow.
Savin briefly describes the Metaflow platform and the goal of simplifying engineering overhead for data scientists and programmers. We discuss how the platform captures snapshots of a project as you work, allowing you to go back in time or share the state of your project with another team member.
We dig into the complicated process of managing dependencies for machine learning and data science projects. Savin describes how the required external libraries can be specified within a flow with the new @pypi or @conda decorators. This allows a project to scale from a local machine to the cloud or multiple instances with all dependencies included.
He talks about starting a new company, Outerbounds, with fellow co-workers from Netflix. Their vision is to continue to build the Metaflow open-source platform and offer customers scalable enterprise-grade infrastructure.
This week’s episode is brought to you by Intel.
Course Spotlight: Everyday Project Packaging With pyproject.toml
In this Code Conversation video course, you’ll learn how to package your everyday projects with pyproject.toml. Playing on the same team as the import system means you can call your project from anywhere, ensure consistent imports, and have one file that’ll work for many build systems.
Topics:
- 00:00:00 – Introduction
- 00:02:25 – Update on Metaflow
- 00:04:13 – What is Outerbounds?
- 00:07:26 – An ML platform to serve data scientists needs
- 00:13:02 – Dependency reproducibility via @conda and @pypi decorators
- 00:26:18 – Sponsor: Intel
- 00:27:10 – Storing lock files along with snapshots
- 00:29:17 – Working alongside code and dependency management systems
- 00:34:03 – Scaling a project from laptop to the cloud
- 00:40:13 – Video Course Spotlight
- 00:41:41 – Getting visibility on processes
- 00:47:23 – Adjusting your project due to GPU availability
- 00:52:27 – Example of jumping back into a project one year later
- 00:55:54 – What are you excited about in the world of Python?
- 00:57:39 – What do you want to learn next?
- 00:59:35 – How can people follow your work online?
- 01:00:19 – Thanks and goodbye
Show Links:
- Metaflow - a framework for real-life ML, AI, and data science
- Infrastructure for ML, AI, and Data Science - Outerbounds
- Human-Friendly, Production-Ready Data Science with Metaflow- Savin Goyal | SciPy 2022 - YouTube
- Episode #61: Scaling Data Science and Machine Learning Infrastructure Like Netflix – The Real Python Podcast
- New in Metaflow: The Long-Awaited @pypi Decorator - Outerbounds
- Managing Dependencies - Metaflow Docs
- Secure ML with Secure Software Dependencies - Outerbounds
- Directed acyclic graph (DAG) - Wikipedia article
- Visualizing Results - Metaflow Docs
- Seamless Data and ML Pipelines with Airflow and Metaflow - Outerbounds
- Episode #142: Orchestrating Large and Small Projects With Apache Airflow – The Real Python Podcast
- Savin (@SavinGoyal) - X
- Savin Goyal - LinkedIn
- Building the ML-driven future - Outerbounds Blog
Level up your Python skills with our expert-led courses:
Next Episode

Wes McKinney on Improving the Data Stack & Composable Systems
How do you avoid the bottlenecks of data processing systems? Is it possible to build tools that decouple storage and computation? This week on the show, creator of the pandas library Wes McKinney is here to discuss Apache Arrow, composable data systems, and community collaboration.
Wes briefly describes the humble beginnings of the pandas project in 2008 and moving the project to open source in 2011. Since then, he’s been thinking about improvements across the data processing ecosystem.
Wes collaborated with members of the broader data science community to build the in-memory analytics infrastructure of Apache Arrow. Arrow avoids the bottlenecks of repeated data serialization and format conversion. He shares examples of Arrow’s use across the spectrum in tools like Polars and DuckDB.
Wes advocates moving from vertically integrated tools toward composable data systems. We discuss his work on Ibis, a portable dataframe API for data manipulation and exploration in Python. Ibis supports multiple backends by decoupling the API from the execution engine.
This week’s episode is brought to you by Posit Connect.
Course Spotlight: Unleashing the Power of the Console With Rich
Rich is a powerful library for creating text-based user interfaces (TUIs) in Python. It enhances code readability by pretty-printing complex data structures and adds visual appeal with colored text, tables, animations, and more.
Topics:
- 00:00:00 – Introduction
- 00:02:26 – Dealing with limitations in early data science
- 00:04:53 – Making pandas open source
- 00:07:10 – Making changes to an existing platform
- 00:12:34 – Decoupling storage and computation
- 00:23:04 – Sponsor: Posit Connect
- 00:23:54 – Apache Arrow solving multiple issues
- 00:27:40 – DuckDB efficient analytic SQL database
- 00:30:24 – Polars dataframe library
- 00:31:04 – pandas 2.0 adding Arrow
- 00:35:56 – Video Course Spotlight
- 00:37:20 – Apache Software Foundation background
- 00:41:29 – Shifting from developer to organizer and collaborator
- 00:45:56 – Creating a portable query layer with Ibis
- 00:55:34 – Casualties of the language wars
- 00:57:57 – What’s your role at Posit?
- 01:01:23 – What are you excited about in the world of Python?
- 01:04:52 – What do you want to learn next?
- 01:06:21 – How can people follow your work online?
- 01:08:20 – Thanks and goodbye
Show Links:
- Wes McKinney - Personal Website
- Wes McKinney - The Road to Composable Data Systems: Thoughts on the Last 15 Years and the Future
- Wes McKinney - Leveling Up the Data Stack: Thoughts on the Last 15 Years - YouTube
- Apache Hadoop
- Cloudera - The hybrid data company
- Wes McKinney - Apache Arrow and the “10 Things I Hate About pandas”
- Voltron Data - The Leading Designer and Builder of Enterprise Data Systems
- Apache Arrow
- DuckDB - An in-process SQL OLAP database management system
- DuckDB-Wasm - Efficient Analytical SQL in the Browser
- Polars - Dataframes for the new era
- pandas 2.2.0 documentation
- Episode #167: Exploring pandas 2.0 & Targets for Apache Arrow – The Real Python Podcast
- ASF - Welcome to The Apache Software Foundation!
- Ursa Labs Blog
- Ibis - The Portable Python dataframe Library
- Python dataframe interchange protocol
- Hadley Wickham
- Rust Programming Language
- italki - Best language learning app with certificated tutors
- Wes McKinney - LinkedIn
- Wes McKinney (@wesmckinn) - X
- Posit - The Open-Source Data Science Company
Level up y...
If you like this episode you’ll love

The Edtech Podcast

The Why And The What – Product Management Podcast

The Art of LiveOps

CodeWinds - Leading edge web developer news and training | javascript / React.js / Node.js / HTML5 / web development - Jeff Barczewski

Joomla Beat Podcast | Web design, development, online marketing, social media & website management
Episode Comments
Featured in these lists
Generate a badge
Get a badge for your website that links back to this episode
<a href="https://goodpods.com/podcasts/the-real-python-podcast-186798/practical-python-decorator-uses-and-avoiding-datetime-pitfalls-44970687"> <img src="https://storage.googleapis.com/goodpods-images-bucket/badges/generic-badge-1.svg" alt="listen to practical python decorator uses & avoiding datetime pitfalls on goodpods" style="width: 225px" /> </a>
Copy