python-usernames


Namepython-usernames JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryPython library to validate usernames suitable for use in public facing applications.
upload_time2023-06-17 13:56:59
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords regex safe security signup user registration username validation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # python-usernames

[![Build
Status](https://travis-ci.org/theskumar/python-usernames.svg?branch=v0.1.0)](https://travis-ci.org/theskumar/python-usernames)
[![Coverage
Status](https://coveralls.io/repos/theskumar/python-usernames/badge.svg?branch=master&service=github)](https://coveralls.io/github/theskumar/python-usernames?branch=master)
[![PyPI
version](https://badge.fury.io/py/python-usernames.svg)](http://badge.fury.io/py/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](https://github.com/theskumar/python-usernames/blob/master/usernames/reserved_words.py)
    that should not be used as username.
-   Python 3.8+

## Installation

    pip install python-usernames

## Usages

```python
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

## Further Reading

-   [Let’s talk about
    usernames](https://www.b-list.org/weblog/2018/feb/11/usernames/)

## Gotchas

Words like `bigcock12` will validated just fine, only equality against
the [banned word
lists](https://github.com/theskumar/python-usernames/blob/master/usernames/reserved_words.py)
is checked. We don't try to be smart to avoid [Scunthorpe
problem](https://en.wikipedia.org/wiki/Scunthorpe_problem). If you can
come up with a algorithm/solution, please create an issue/pr :).

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "python-usernames",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "regex,safe,security,signup,user registration,username,validation",
    "author": "",
    "author_email": "Saurabh Kumar <python-usernames@saurabh-kumar.com>",
    "download_url": "https://files.pythonhosted.org/packages/e4/0d/aad0e8609ad208f3972d9032266f452e04ef9919f8db7f9dab06f49782c7/python_usernames-1.0.0.tar.gz",
    "platform": null,
    "description": "# python-usernames\n\n[![Build\nStatus](https://travis-ci.org/theskumar/python-usernames.svg?branch=v0.1.0)](https://travis-ci.org/theskumar/python-usernames)\n[![Coverage\nStatus](https://coveralls.io/repos/theskumar/python-usernames/badge.svg?branch=master&service=github)](https://coveralls.io/github/theskumar/python-usernames?branch=master)\n[![PyPI\nversion](https://badge.fury.io/py/python-usernames.svg)](http://badge.fury.io/py/python-usernames)\n\nPython library to validate usernames suitable for use in public facing\napplications where use can choose login names and sub-domains.\n\n## Features\n\n-   Provides a default regex validator\n-   Validates against list of [banned\n    words](https://github.com/theskumar/python-usernames/blob/master/usernames/reserved_words.py)\n    that should not be used as username.\n-   Python 3.8+\n\n## Installation\n\n    pip install python-usernames\n\n## Usages\n\n```python\nfrom python_usernames import is_safe_username\n\n>>> is_safe_username(\"jerk\")\nFalse  # contains one of the banned words\n\n>>> is_safe_username(\"handsome!\")\nFalse  # contains non-url friendly `!`\n```\n\n**is\\_safe\\_username** takes the following optional arguments:\n\n-   `whitelist`: a case insensitive list of words that should be\n    considered as always safe. Default: `[]`\n-   `blacklist`: a case insensitive list of words that should be\n    considered as unsafe. Default: `[]`\n-   `max_length`: specify the maximun character a username can have.\n    Default: `None`\n\n- `regex`: regular expression string that must pass before the banned\n:   words is checked.\n\nThe default regular expression is as follows:\n\n    ^                       # beginning of string\n    (?!_$)                  # no only _\n    (?![-.])                # no - or . at the beginning\n    (?!.*[_.-]{2})          # no __ or _. or ._ or .. or -- inside\n    [a-zA-Z0-9_.-]+         # allowed characters, atleast one must be present\n    (?<![.-])               # no - or . at the end\n    $                       # end of string\n\n## Further Reading\n\n-   [Let\u2019s talk about\n    usernames](https://www.b-list.org/weblog/2018/feb/11/usernames/)\n\n## Gotchas\n\nWords like `bigcock12` will validated just fine, only equality against\nthe [banned word\nlists](https://github.com/theskumar/python-usernames/blob/master/usernames/reserved_words.py)\nis checked. We don't try to be smart to avoid [Scunthorpe\nproblem](https://en.wikipedia.org/wiki/Scunthorpe_problem). If you can\ncome up with a algorithm/solution, please create an issue/pr :).\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python library to validate usernames suitable for use in public facing applications.",
    "version": "1.0.0",
    "project_urls": {
        "Documentation": "https://github.com/theskumar/python-usernames/tree/main#readme",
        "Source": "https://github.com/theskumar/python-usernames",
        "Tracker": "https://github.com/theskumar/python-usernames/issues"
    },
    "split_keywords": [
        "regex",
        "safe",
        "security",
        "signup",
        "user registration",
        "username",
        "validation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5f4fd0f708985dceefcb8e9cb1eefe2b5f3d88b624ec927bb85fa69f89de8f50",
                "md5": "64ac70942f76381c0e46d4b1167631fb",
                "sha256": "59fd41670d8ee550f93be1db25fb0112591b0566c44069d6d42ad26a5c71b474"
            },
            "downloads": -1,
            "filename": "python_usernames-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "64ac70942f76381c0e46d4b1167631fb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5882,
            "upload_time": "2023-06-17T13:56:58",
            "upload_time_iso_8601": "2023-06-17T13:56:58.532227Z",
            "url": "https://files.pythonhosted.org/packages/5f/4f/d0f708985dceefcb8e9cb1eefe2b5f3d88b624ec927bb85fa69f89de8f50/python_usernames-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e40daad0e8609ad208f3972d9032266f452e04ef9919f8db7f9dab06f49782c7",
                "md5": "c5a8f98aaf89254491f288c7e96fd7d8",
                "sha256": "82c68b9dccb6d0571eded31fe47b91ebca4b25e530a8703e8c06ebd9198f3f4f"
            },
            "downloads": -1,
            "filename": "python_usernames-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c5a8f98aaf89254491f288c7e96fd7d8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4993,
            "upload_time": "2023-06-17T13:56:59",
            "upload_time_iso_8601": "2023-06-17T13:56:59.427774Z",
            "url": "https://files.pythonhosted.org/packages/e4/0d/aad0e8609ad208f3972d9032266f452e04ef9919f8db7f9dab06f49782c7/python_usernames-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-17 13:56:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "theskumar",
    "github_project": "python-usernames",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "python-usernames"
}
        
Elapsed time: 0.08007s