PyBeach 2025

pathlib: why and how to use it
2025-09-27 , Venue

If your Python code works with file paths, you should be using pathlib. This standard library module may seem a bit cumbersome at first, but pathlib-using code is often more readable the alternative.

Python's many path-oriented utilities used to expect a string representation for all file paths. That's not the case anymore. Now, every important path-consuming library will accept pathlib.Path objects.

During this talk, we'll see why pathlib.Path objects make for more maintainable code. We'll visit a number of useful pathlib examples and recipes along the way.

By the end of this talk, you'll be tempted to convert all your path-handling code to use pathlib.

Trey Hunner specializes in Python education and corporate training. Trey is a former Python Software Foundation Board Director, a San Diego Python meetup regular. You can learn from Trey through his Python Morsels platform and his weekly Python tips newsletter.