python-usernames
Python library to validate usernames suitable for use in public facing applications where use can choose login names and sub-domains.
Features
- Provides a default regex validator
- Validates against list of banned words that should not be used as username.
- Python 3.8+
Installation
pip install python-usernames
Usages
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
Credits
Further Reading
Gotchas
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 :).
License
MIT
Metadata
Release files for python-usernames 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_usernames-1.1.0.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_usernames-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / python_usernames-1.1.0.tar.gz
| Download URL | python_usernames-1.1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2db10779467405d1dc5307e7ea4faf96d35a03851f44732fcce2693d2a9f791f
|
|
BLAKE2b-256 checksum How to use checksums |
79c6ee77a710d1efd100f3d2ae4d5f97807d64e7253c84066a5b1dcfb16b7d48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2025.
Transparency logRelease files / python_usernames-1.1.0-py3-none-any.whl
| Download URL | python_usernames-1.1.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc75c6000bd7875d866188467cebf764230fad0cb0112cec381d665ab53df0ee
|
|
BLAKE2b-256 checksum How to use checksums |
dfe661e2f48dc7ca49b646b54ae65484aaff74b2f806db9ef40ac78de8481d2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2025.
Transparency log