A Python library to sanitize/validate a string such as filenames/file-paths/etc.
Project description
pathvalidate
Summary
A Python library to sanitize/validate a string such as filenames/file-paths/etc.
Features
- Sanitize/Validate a string as a:
file name
file path
Multibyte character support
Examples
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!
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
For more information
More examples are available 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
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.23.0.tar.gz
(18.7 kB
view hashes)
Built Distribution
Close
Hashes for pathvalidate-0.23.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0978348a69f1613ef4e6def14bda3658801f68fd05ed958e09d853471733f3d3 |
|
MD5 | 98090da0c6bca6ec55930b9875f11bd8 |
|
BLAKE2b-256 | 6d9674a55c34795c1bc0196f0068d71b54c94733de8c107dc757db6208f9e156 |