--- id: pathvalidate version: "3.3.1" license: MIT License license_treatment: permissive maintenance: active --- # pathvalidate — pathvalidate is a Python library to sanitize/validate a string such as filenames/file-paths/etc. License: permissive · Maintenance: active · Downloads: 20.6M/mo ## 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 above — 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 pip install pathvalidate uv add pathvalidate 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