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.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.0.dev3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48c39154054a9446f4812d977a5151cef641ee2ca191f04a050b563f14722c96 |
|
MD5 | 0160f277717128a82e989cf850ab9647 |
|
BLAKE2b-256 | 4ef49021e038373b67794bad6fa0248a2ccb84ca3e8f956fc3ceb8bedf4ff40e |
Close
Hashes for sanitize_filename-1.0.0.dev3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f21b5aa302af66939e9efd6dfff3a38ded47e636baa644f5b04bf5a4d838dcbf |
|
MD5 | 17dd1462686998ffaa5a9406b60b4f43 |
|
BLAKE2b-256 | 329aa31d7a82e93aa18d2ad37cb05fc3168238754c6efaa3f9a8f3dd86747ffa |