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-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.dev1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d8d9174e391999e2ba4faee827b0cab44f9466b4e6500d9118c854c5b6d2e33 |
|
MD5 | e17c12c3a81ea66869aa29af29685486 |
|
BLAKE2b-256 | ca4e1a50a857e2e6a74990fb9b18a426d4db02e62ec49ac54bdbaabf28320452 |
Close
Hashes for sanitize_filename-1.0.0.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 491ef64eb84ee4ddd1a6a98a217e638ed3e8fd7e8e17429e87216aea846c3ed2 |
|
MD5 | db60f3430e7b945f47f64f6f1b636fe6 |
|
BLAKE2b-256 | a78d93f703ac279351d7f94c8fe7a53c038b768149a39f4b06f118d7e2f8c522 |