A permissive filename sanitizer.
Project description
A simple, dependency-free, blacklist-based filename sanitizer, for when you want to keep the original filename.
Note that a blacklist based sanitizer will never be as safe as a whitelist based one. In most cases, your best option is to create a safe filename yourself. Your second safest option is to use a whitelist approach (allowing only certain characters). This sanitizer is useful when you want to keep the original filename, including non ascii characters, whenever possible.
Installation
pip install sanitize_filename
Usage
from sanitize_filename import sanitize
filename = input("Enter a file name:")
filename = sanitize(filename)
Examples:
> sanitize("A/B/C.txt")
'ABC.txt'
> sanitize("this𓀦filenameḜisあactually...valid.txt")
'this𓀦filenameḜisあactually...valid.txt'
> sanitize("def.")
'def'
> sanitize("NUL")
'__NUL'
> sanitize("..")
'__'
Changelog
-
1.0.1
- First release (as 1.0.1 due to a version number mix-up in 1.0.0)
-
1.0.0-dev3
- Black list low code point characters (<32)
-
1.0.0-dev1
- First version
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
Built Distribution
Close
Hashes for sanitize_filename-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47869a414bf239d2b868244135a34131edc3bdc067aba713d1e469d93aa6f176 |
|
MD5 | 583a470b3eb141c8a8827c5809eb81ce |
|
BLAKE2b-256 | 096bf4ef1007116e8d007a0d08076024e927aa537fecd99c1295f4430d01f2e2 |