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

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

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.23.1.tar.gz (19.0 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.23.1-py2.py3-none-any.whl (19.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: pathvalidate-0.23.1.tar.gz
  • Upload date:
  • Size: 19.0 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.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

File hashes

Hashes for pathvalidate-0.23.1.tar.gz
Algorithm Hash digest
SHA256 8e0816dbd115670356c6bbd5a01609b7c20b39c3528e40e713fbe8c512a79e5f
MD5 aeaf4682a0af2f96a6b1a11bef99c504
BLAKE2b-256 6780c365d0ee6a10382653c3546e3bae041c87b56c055ba7fa882b006fdc214f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pathvalidate-0.23.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.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.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

File hashes

Hashes for pathvalidate-0.23.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6280becaa77f5dcc80bf09080839075d8c05d46f8c70f7b9a07664c69f304f25
MD5 152974f6a28d9187509100d96962a117
BLAKE2b-256 6f56efbdf53d8f7e127d32e4921170c6a0d1df3c5483eec5a48ac3bdbf9af1f7

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