GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - theskumar/python-usernames: Ensures usernames are URL-friendly. No abusive/reserved words.

BranchesTags
Open more actions menu

Latest commit

 

History

56 Commits
56 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
scripts
scripts
 
 
src/python_usernames
src/python_usernames
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.python-version
.python-version
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 
uv.lock
uv.lock
 
 

Repository files navigation

python-usernames

Test PyPI version Python Versions

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

  • The-Big-Username-Blocklist
  • Profanity-filter

Further Reading

  • Let’s talk about usernames

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 :).

Development

This project uses uv for dependency management and packaging.

Setup

  1. Install uv:

    curl -LsSf https://astral.sh/uv/install.sh | sh
  2. Clone the repository and sync dependencies:

    git clone https://github.com/theskumar/python-usernames.git
    cd python-usernames
    uv sync --all-groups

Running Tests

uv run pytest

Linting

uv run ruff check .
uv run black --check .

Building

uv build

License

MIT

About

Ensures usernames are URL-friendly. No abusive/reserved words.

Resources

Readme
Activity

Stars

104 stars

Watchers

7 watching

Forks

12 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.