{"id":13545700,"url":"https://github.com/thombashi/pathvalidate","last_synced_at":"2025-05-15T13:09:01.015Z","repository":{"id":38419732,"uuid":"54639247","full_name":"thombashi/pathvalidate","owner":"thombashi","description":"A Python library to sanitize/validate a string such as filenames/file-paths/etc.","archived":false,"fork":false,"pushed_at":"2025-03-02T07:13:18.000Z","size":897,"stargazers_count":251,"open_issues_count":8,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-08T09:02:25.438Z","etag":null,"topics":["filepath","lint","python-library","sanitization","validation-library"],"latest_commit_sha":null,"homepage":"https://pathvalidate.rtfd.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thombashi.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"thombashi","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"thombashi","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2016-03-24T12:11:39.000Z","updated_at":"2025-05-07T01:36:48.000Z","dependencies_parsed_at":"2023-12-15T02:18:08.992Z","dependency_job_id":"56f090e9-d889-44c6-8ead-513b18fe2db0","html_url":"https://github.com/thombashi/pathvalidate","commit_stats":{"total_commits":1199,"total_committers":10,"mean_commits":119.9,"dds":"0.29190992493744783","last_synced_commit":"1e8d335c257597f27c9ac85fba0a8528a05079b6"},"previous_names":[],"tags_count":78,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fpathvalidate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fpathvalidate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fpathvalidate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fpathvalidate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thombashi","download_url":"https://codeload.github.com/thombashi/pathvalidate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346623,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filepath","lint","python-library","sanitization","validation-library"],"created_at":"2024-08-01T11:01:10.284Z","updated_at":"2025-05-15T13:08:56.619Z","avatar_url":"https://github.com/thombashi.png","language":"Python","funding_links":["https://github.com/sponsors/thombashi","https://liberapay.com/thombashi"],"categories":["Python"],"sub_categories":[],"readme":".. contents:: **pathvalidate**\n   :backlinks: top\n   :depth: 2\n\nSummary\n=========\n`pathvalidate \u003chttps://github.com/thombashi/pathvalidate\u003e`__ is a Python library to sanitize/validate a string such as filenames/file-paths/etc.\n\n|PyPI pkg ver| |conda pkg ver| |Supported Python ver| |Supported Python impl| |CI status| |Test coverage| |CodeQL|\n\n.. |PyPI pkg ver| image:: https://badge.fury.io/py/pathvalidate.svg\n    :target: https://badge.fury.io/py/pathvalidate\n    :alt: PyPI package version\n\n.. |conda pkg ver| image:: https://anaconda.org/conda-forge/pathvalidate/badges/version.svg\n    :target: https://anaconda.org/conda-forge/pathvalidate\n    :alt: conda package version\n\n.. |Supported Python ver| image:: https://img.shields.io/pypi/pyversions/pathvalidate.svg\n    :target: https://pypi.org/project/pathvalidate\n    :alt: Supported Python versions\n\n.. |Supported Python impl| image:: https://img.shields.io/pypi/implementation/pathvalidate.svg\n    :target: https://pypi.org/project/pathvalidate\n    :alt: Supported Python implementations\n\n.. |CI status| image:: https://github.com/thombashi/pathvalidate/actions/workflows/ci.yml/badge.svg\n    :target: https://github.com/thombashi/pathvalidate/actions/workflows/ci.yml\n    :alt: CI status of Linux/macOS/Windows\n\n.. |Test coverage| image:: https://coveralls.io/repos/github/thombashi/pathvalidate/badge.svg?branch=master\n    :target: https://coveralls.io/github/thombashi/pathvalidate?branch=master\n    :alt: Test coverage: coveralls\n\n.. |CodeQL| image:: https://github.com/thombashi/pathvalidate/actions/workflows/github-code-scanning/codeql/badge.svg\n    :target: https://github.com/thombashi/pathvalidate/actions/workflows/github-code-scanning/codeql\n    :alt: CodeQL\n\nFeatures\n---------\n- Sanitize/Validate a string as a:\n    - file name\n    - file path\n- Sanitize will do:\n    - Remove invalid characters for a target platform\n    - Replace reserved names for a target platform\n    - Normalize\n    - Remove unprintable characters\n- Argument validator/sanitizer for ``argparse`` and ``click``\n- Multi platform support:\n    - ``Linux``\n    - ``Windows``\n    - ``macOS``\n    - ``POSIX``: POSIX-compliant systems (Linux, macOS, etc.)\n    - ``universal``: platform independent\n- Multibyte character support\n\nCLI tool\n---------\nYou can find this package's command line interface tool at the `pathvalidate-cli \u003chttps://github.com/thombashi/pathvalidate-cli\u003e`__ repository.\n\nExamples\n==========\nSanitize a filename\n---------------------\n:Sample Code:\n    .. code-block:: python\n\n        from pathvalidate import sanitize_filename\n\n        fname = \"fi:l*e/p\\\"a?t\u003eh|.t\u003cxt\"\n        print(f\"{fname} -\u003e {sanitize_filename(fname)}\\n\")\n\n        fname = \"\\0_a*b:c\u003cd\u003ee%f/(g)h+i_0.txt\"\n        print(f\"{fname} -\u003e {sanitize_filename(fname)}\\n\")\n\n:Output:\n    .. code-block::\n\n        fi:l*e/p\"a?t\u003eh|.t\u003cxt -\u003e filepath.txt\n\n        _a*b:c\u003cd\u003ee%f/(g)h+i_0.txt -\u003e _abcde%f(g)h+i_0.txt\n\nThe default target ``platform`` is ``universal``.\ni.e. the sanitized file name is valid for any platform.\n\nSanitize a filepath\n---------------------\n:Sample Code:\n    .. code-block:: python\n\n        from pathvalidate import sanitize_filepath\n\n        fpath = \"fi:l*e/p\\\"a?t\u003eh|.t\u003cxt\"\n        print(f\"{fpath} -\u003e {sanitize_filepath(fpath)}\\n\")\n\n        fpath = \"\\0_a*b:c\u003cd\u003ee%f/(g)h+i_0.txt\"\n        print(f\"{fpath} -\u003e {sanitize_filepath(fpath)}\\n\")\n\n:Output:\n    .. code-block::\n\n        fi:l*e/p\"a?t\u003eh|.t\u003cxt -\u003e file/path.txt\n\n        _a*b:c\u003cd\u003ee%f/(g)h+i_0.txt -\u003e _abcde%f/(g)h+i_0.txt\n\nValidate a filename\n---------------------\n:Sample Code:\n    .. code-block:: python\n\n        import sys\n        from pathvalidate import ValidationError, validate_filename\n\n        try:\n            validate_filename(\"fi:l*e/p\\\"a?t\u003eh|.t\u003cxt\")\n        except ValidationError as e:\n            print(f\"{e}\\n\", file=sys.stderr)\n\n        try:\n            validate_filename(\"COM1\")\n        except ValidationError as e:\n            print(f\"{e}\\n\", file=sys.stderr)\n\n:Output:\n    .. code-block::\n\n        [PV1100] invalid characters found: platform=universal, description=invalids=('/'), value='fi:l*e/p\"a?t\u003eh|.t\u003cxt'\n\n        [PV1002] found a reserved name by a platform: 'COM1' is a reserved name, platform=universal, reusable_name=False\n\nCheck a filename\n------------------\n:Sample Code:\n    .. code-block:: python\n\n        from pathvalidate import is_valid_filename, sanitize_filename\n\n        fname = \"fi:l*e/p\\\"a?t\u003eh|.t\u003cxt\"\n        print(f\"is_valid_filename('{fname}') return {is_valid_filename(fname)}\\n\")\n\n        sanitized_fname = sanitize_filename(fname)\n        print(f\"is_valid_filename('{sanitized_fname}') return {is_valid_filename(sanitized_fname)}\\n\")\n\n:Output:\n    .. code-block::\n\n        is_valid_filename('fi:l*e/p\"a?t\u003eh|.t\u003cxt') return False\n\n        is_valid_filename('filepath.txt') return True\n\nfilename/filepath validator for ``argparse``\n----------------------------------------------\n:Sample Code:\n    .. code-block:: python\n\n        from argparse import ArgumentParser\n\n        from pathvalidate.argparse import validate_filename_arg, validate_filepath_arg\n\n        parser = ArgumentParser()\n        parser.add_argument(\"--filename\", type=validate_filename_arg)\n        parser.add_argument(\"--filepath\", type=validate_filepath_arg)\n        options = parser.parse_args()\n\n        if options.filename:\n            print(f\"filename: {options.filename}\")\n\n        if options.filepath:\n            print(f\"filepath: {options.filepath}\")\n\n:Output:\n    .. code-block::\n\n        $ ./examples/argparse_validate.py --filename eg\n        filename: eg\n        $ ./examples/argparse_validate.py --filename e?g\n        usage: argparse_validate.py [-h] [--filename FILENAME] [--filepath FILEPATH]\n        argparse_validate.py: error: argument --filename: [PV1100] invalid characters found: invalids=(':'), value='e:g', platform=Windows\n\n.. note::\n    ``validate_filepath_arg`` consider ``platform`` as of ``\"auto\"`` if the input is an absolute file path.\n\nfilename/filepath sanitizer for ``argparse``\n----------------------------------------------\n:Sample Code:\n    .. code-block:: python\n\n        from argparse import ArgumentParser\n\n        from pathvalidate.argparse import sanitize_filename_arg, sanitize_filepath_arg\n\n\n        parser = ArgumentParser()\n        parser.add_argument(\"--filename\", type=sanitize_filename_arg)\n        parser.add_argument(\"--filepath\", type=sanitize_filepath_arg)\n        options = parser.parse_args()\n\n        if options.filename:\n            print(\"filename: {}\".format(options.filename))\n\n        if options.filepath:\n            print(\"filepath: {}\".format(options.filepath))\n\n:Output:\n    .. code-block::\n\n        $ ./examples/argparse_sanitize.py --filename e/g\n        filename: eg\n\n.. note::\n    ``sanitize_filepath_arg`` is set platform as ``\"auto\"``.\n\nfilename/filepath validator for ``click``\n-------------------------------------------\n:Sample Code:\n    .. code-block:: python\n\n        import click\n\n        from pathvalidate.click import validate_filename_arg, validate_filepath_arg\n\n\n        @click.command()\n        @click.option(\"--filename\", callback=validate_filename_arg)\n        @click.option(\"--filepath\", callback=validate_filepath_arg)\n        def cli(filename: str, filepath: str) -\u003e None:\n            if filename:\n                click.echo(f\"filename: {filename}\")\n            if filepath:\n                click.echo(f\"filepath: {filepath}\")\n\n\n        if __name__ == \"__main__\":\n            cli()\n\n:Output:\n    .. code-block::\n\n        $ ./examples/click_validate.py --filename ab\n        filename: ab\n        $ ./examples/click_validate.py --filepath e?g\n        Usage: click_validate.py [OPTIONS]\n        Try 'click_validate.py --help' for help.\n\n        Error: Invalid value for '--filename': [PV1100] invalid characters found: invalids=('?'), value='e?g', platform=Windows\n\nfilename/filepath sanitizer for ``click``\n-------------------------------------------\n:Sample Code:\n    .. code-block:: python\n\n        import click\n\n        from pathvalidate.click import sanitize_filename_arg, sanitize_filepath_arg\n\n\n        @click.command()\n        @click.option(\"--filename\", callback=sanitize_filename_arg)\n        @click.option(\"--filepath\", callback=sanitize_filepath_arg)\n        def cli(filename, filepath):\n            if filename:\n                click.echo(f\"filename: {filename}\")\n            if filepath:\n                click.echo(f\"filepath: {filepath}\")\n\n\n        if __name__ == \"__main__\":\n            cli()\n\n:Output:\n    .. code-block::\n\n        $ ./examples/click_sanitize.py --filename a/b\n        filename: ab\n\nFor more information\n----------------------\nMore examples can be found at \nhttps://pathvalidate.rtfd.io/en/latest/pages/examples/index.html\n\nInstallation\n============\nInstallation: pip\n------------------------------\n::\n\n    pip install pathvalidate\n\nInstallation: conda\n------------------------------\n::\n\n    conda install conda-forge::pathvalidate\n\nInstallation: apt\n------------------------------\n::\n\n    sudo add-apt-repository ppa:thombashi/ppa\n    sudo apt update\n    sudo apt install python3-pathvalidate\n\n\nDependencies\n============\nPython 3.9+\nno external dependencies.\n\nDocumentation\n===============\nhttps://pathvalidate.rtfd.io/\n\nSponsors\n====================================\n|chasbecker| |shiguredo| |b4tman| |Arturi0| |github|\n\n.. |chasbecker| image:: https://avatars.githubusercontent.com/u/44389260?s=48\u0026u=6da7176e51ae2654bcfd22564772ef8a3bb22318\u0026v=4\n   :target: https://github.com/chasbecker\n   :alt: ex-sponsor: Charles Becker (chasbecker)\n.. |shiguredo| image:: https://avatars.githubusercontent.com/u/2549434?s=48\u0026v=4\n   :target: https://github.com/shiguredo\n   :alt: ex-sponsor: 時雨堂 (shiguredo)\n.. |b4tman| image:: https://avatars.githubusercontent.com/u/3658062?s=48\u0026v=4\n   :target: https://github.com/b4tman\n   :alt: onetime: Dmitry Belyaev (b4tman)\n.. |Arturi0| image:: https://avatars.githubusercontent.com/u/46711571?s=48\u0026u=57687c0e02d5d6e8eeaf9177f7b7af4c9f275eb5\u0026v=4\n   :target: https://github.com/Arturi0\n   :alt: onetime: Arturi0\n.. |github| image:: https://avatars.githubusercontent.com/u/9919?s=48\u0026v=4\n   :target: https://github.com/github\n   :alt: onetime: GitHub (github)\n\n`Become a sponsor \u003chttps://github.com/sponsors/thombashi\u003e`__\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthombashi%2Fpathvalidate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthombashi%2Fpathvalidate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthombashi%2Fpathvalidate/lists"}