| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Python library to validate usernames suitable for use in public facing applications where use can choose login names and sub-domains.
pip install python-usernames
from python_usernames import is_safe_username
>>> is_safe_username("jerk")
False # contains one of the banned words
>>> is_safe_username("handsome!")
False # contains non-url friendly `!`is_safe_username takes the following optional arguments:
whitelist: a case insensitive list of words that should be considered as always safe. Default: []
blacklist: a case insensitive list of words that should be considered as unsafe. Default: []
max_length: specify the maximun character a username can have. Default: None
regex: regular expression string that must pass before the banned : words is checked.
The default regular expression is as follows:
^ # beginning of string
(?!_$) # no only _
(?![-.]) # no - or . at the beginning
(?!.*[_.-]{2}) # no __ or _. or ._ or .. or -- inside
[a-zA-Z0-9_.-]+ # allowed characters, atleast one must be present
(?<![.-]) # no - or . at the end
$ # end of string
Words like bigcock12 will validated just fine, only equality against the banned word lists is checked. We don't try to be smart to avoid Scunthorpe problem. If you can come up with a algorithm/solution, please create an issue/pr :).
This project uses uv for dependency management and packaging.
Install uv:
curl -LsSf https://astral.sh/uv/install.sh | shClone the repository and sync dependencies:
git clone https://github.com/theskumar/python-usernames.git
cd python-usernames
uv sync --all-groupsuv run pytestuv run ruff check .
uv run black --check .uv buildMIT
| Back | FazBrowse Home | New Git URL |