Skip to main content

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

Project description

Summary

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

PyPI package version Supported Python versions Linux/macOS CI status Windows CI status Test coverage GitHub stars

Features

  • Sanitize/Validate a string as a:
    • file name

    • file path

  • Multibyte character support

Examples

Sanitize a filename

Sample Code:
from pathvalidate import sanitize_filename

fname = "fi:l*e/p\"a?t>h|.t<xt"
print("{} -> {}".format(fname, sanitize_filename(fname)))

fname = "\0_a*b:c<d>e%f/(g)h+i_0.txt"
print("{} -> {}".format(fname, sanitize_filename(fname)))
Output:
fi:l*e/p"a?t>h|.t<xt -> filepath.txt
_a*b:c<d>e%f/(g)h+i_0.txt -> _abcde%f(g)h+i_0.txt

Sanitize a filepath

Sample Code:
from pathvalidate import sanitize_filepath

fpath = "fi:l*e/p\"a?t>h|.t<xt"
print("{} -> {}".format(fpath, sanitize_filepath(fpath)))

fpath = "\0_a*b:c<d>e%f/(g)h+i_0.txt"
print("{} -> {}".format(fpath, sanitize_filepath(fpath)))
Output:
fi:l*e/p"a?t>h|.t<xt -> file/path.txt
_a*b:c<d>e%f/(g)h+i_0.txt -> _abcde%f/(g)h+i_0.txt

Validate a filename

Sample Code:
from pathvalidate import validate_filename

try:
    validate_filename("\0_a*b:c<d>e%f/(g)h+i_0.txt")
except ValueError:
    print("invalid filename!")
Output:
invalid filename!

For more information

More More examples can be found at https://pathvalidate.rtfd.io/en/latest/pages/examples/index.html

Installation

pip install pathvalidate

Dependencies

Python 2.7+ or 3.4+ No external dependencies.

Test dependencies

Documentation

https://pathvalidate.rtfd.io/

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathvalidate-0.24.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pathvalidate-0.24.0-py2.py3-none-any.whl (12.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pathvalidate-0.24.0.tar.gz.

File metadata

  • Download URL: pathvalidate-0.24.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.2 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for pathvalidate-0.24.0.tar.gz
Algorithm Hash digest
SHA256 af4dc36088298b061bf2accdd83a3456655d66e01052bfbdae43dea9685b4983
MD5 892ee59eca0fa45c6a054e726dfe930d
BLAKE2b-256 f84ba863e7b843df7044c6a4d72aa3a1d3d8a4aebc548ab119fa0f80d1403de5

See more details on using hashes here.

File details

Details for the file pathvalidate-0.24.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pathvalidate-0.24.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.2 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for pathvalidate-0.24.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 53fcd506a4dc1b27c3253e0850d1ca4c7024aee1ba8ffe72df3e84941c9e15cf
MD5 3cb572caeee49759dbbb1d76b092b4a4
BLAKE2b-256 09b791c779647252d4ff34f2502ba26edd3827219df688890905e6650bb4c22f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page