skillfed

pathvalidate

pathvalidate is a Python library to sanitize/validate a string such as filenames/file-paths/etc.

pathvalidate v3.3.1 20.6M downloads/30d#1,032 on PyPI294
Permissive license MIT License Active released

What it is and what it does

pathvalidate is a Python library that cleans and validates filenames and file paths by removing or replacing characters that are invalid, reserved, or unprintable on target platforms. It handles platform-specific rules for Linux, Windows, macOS, POSIX, and universal (cross-platform) contexts, and includes support for multibyte characters. The library provides both standalone functions and integrations with argparse and click for command-line argument validation and sanitization.

You use it when you need to accept user input or external data as filenames or paths and ensure they will work on your target platform without errors. It removes problematic characters, replaces reserved names (like COM1 on Windows), normalizes whitespace, and strips unprintable characters—all without external dependencies.

Use it for:

  • Sanitize user-supplied filenames in web applications or file upload handlers before writing to disk.
  • Validate file paths in CLI tools using argparse or click to reject invalid input early.
  • Clean batch-imported filenames from external sources (APIs, databases, archives) for cross-platform compatibility.
  • Normalize path strings in data pipelines to prevent filesystem errors across development, staging, and production environments.
  • Check whether a string is a valid filename before attempting file operations to provide clear error messages.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Sanitize and validate filenames and file paths by removing or replacing invalid characters, reserved names, and unprintable characters across multiple platforms (Linux, Windows, macOS, POSIX, and universal).

Yes. pathvalidate is a focused, well-maintained library with zero dependencies, permissive licensing, and active development. Install it if you need reliable filename or path validation across platforms; the low friction and clear API make it a straightforward addition to any project handling file I/O.

Install

pathvalidate on PyPI

pip

pip install pathvalidate

uv

uv add pathvalidate

poetry

poetry add pathvalidate

Installing pathvalidate

Before you install

Low friction: zero runtime dependencies, pure Python wheel distribution. Actively maintained with recent commits and stable production status.

License in practice

MIT License (permissive): you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.

Quickstart

pip install pathvalidate

from pathvalidate import sanitize_filename, validate_filename

fname = "fi:l*e/p\"a?t>h|.t<xt"
print(sanitize_filename(fname))  # Returns valid filename
validate_filename(fname)  # Raises ValidationError if invalid

Requires Python 3.9 or later.

Verify before relying

  • Whether multibyte character support covers all Unicode normalization edge cases across platforms.
  • Performance characteristics when sanitizing very long paths or batch processing large filename lists.

Package facts

License MIT License (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 425 days since the last release
Last repo commit
First released
Downloads 20,577,101/month — #1,032 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pathvalidate-3.3.1-py3-none-any.whl

Keywords: file, path, validation, validator, sanitization, sanitizer

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: System :: FilesystemsTopic :: Text ProcessingTyping :: Typed

Tags

filename validationsanitize file pathsinvalid character removalcross-platform path validationreserved name handlingfilename sanitizerpath validation library
filesysteminput-validationcross-platform

More Libraries packages