Skip to main content

A Python library to sanitize/validate a string such as filenames/file-paths/variable-names/etc.

Project description

pathvalidate

https://badge.fury.io/py/pathvalidate.svg https://img.shields.io/pypi/pyversions/pathvalidate.svg Linux CI test status Windows CI test status https://coveralls.io/repos/github/thombashi/pathvalidate/badge.svg?branch=master https://img.shields.io/github/stars/thombashi/pathvalidate.svg?style=social&label=Star

Summary

A Python library to sanitize/validate a string such as filenames/file-paths/variable-names/etc.

Features

  • Sanitize/Validate a string as a:

Examples

Validate a filename

Sample Code:
import pathvalidate

try:
    pathvalidate.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:
import pathvalidate as pv

print(pv.sanitize_filename("f\\i:l*e?n\"a<m>e|.txt"))
print(pv.sanitize_filename("_a*b:c<d>e%f/(g)h+i_0.txt"))
Output:
_abcde%f(g)h+i_0.txt

Sanitize a filepath

Sample Code:
import pathvalidate as pv

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

Sanitize a variable name

Sample Code:
import pathvalidate as pv

print(pv.sanitize_python_var_name("_a*b:c<d>e%f/(g)h+i_0.txt"))
Output:
abcdefghi_0txt

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

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
pathvalidate-0.21.4-py2.py3-none-any.whl (18.7 kB) Copy SHA256 hash SHA256 Wheel py2.py3
pathvalidate-0.21.4.tar.gz (18.9 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page