Skip to main content

Python library to validate usernames suitable for use in public facing applications.

Project description

python-usernames

Build Status Coverage Status PyPI version

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_usernames-1.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_usernames-1.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file python_usernames-1.1.0.tar.gz.

File metadata

  • Download URL: python_usernames-1.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_usernames-1.1.0.tar.gz
Algorithm Hash digest
SHA256 2db10779467405d1dc5307e7ea4faf96d35a03851f44732fcce2693d2a9f791f
MD5 585bc0bbe487d5a2c66acc08012bb934
BLAKE2b-256 79c6ee77a710d1efd100f3d2ae4d5f97807d64e7253c84066a5b1dcfb16b7d48

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_usernames-1.1.0.tar.gz:

Publisher: release.yml on theskumar/python-usernames

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_usernames-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_usernames-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc75c6000bd7875d866188467cebf764230fad0cb0112cec381d665ab53df0ee
MD5 efe6953321ec3be9a51ac567e003b70d
BLAKE2b-256 dfe661e2f48dc7ca49b646b54ae65484aaff74b2f806db9ef40ac78de8481d2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_usernames-1.1.0-py3-none-any.whl:

Publisher: release.yml on theskumar/python-usernames

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page