this actually came up fairly recently on this very list -- go poke around in the archives to find it.

But the short version is that there is no clear definition of a "sanitized" filename -- see that SO thread to get the idea. So you really want a solution that works for your use case, so not really a candidate for the standard library.

There are a number of packages on PyPi that might help:

just to name two.


On Tue, Aug 11, 2020 at 10:51 PM Charles Machalow <> wrote:
I was reading and was thinking that functionality to create safe paths from unsafe paths and check if a Path would work on a given filesystem would well in Pathlib.
Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct:

Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython