{"id":13520192,"url":"https://github.com/snguyenthanh/better_profanity","last_synced_at":"2025-03-31T16:30:58.193Z","repository":{"id":38900939,"uuid":"157077840","full_name":"snguyenthanh/better_profanity","owner":"snguyenthanh","description":"Blazingly fast cleaning swear words (and their leetspeak) in strings","archived":false,"fork":false,"pushed_at":"2024-05-23T08:27:31.000Z","size":360,"stargazers_count":211,"open_issues_count":29,"forks_count":70,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-28T17:19:12.580Z","etag":null,"topics":["censor","censored-words","censorship","leetspeak","profanity","python","words"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/snguyenthanh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-11T12:35:33.000Z","updated_at":"2024-10-23T10:48:09.000Z","dependencies_parsed_at":"2024-06-18T14:01:12.846Z","dependency_job_id":"d577bc7e-4c76-48b8-ab35-6d0f2eeabc5d","html_url":"https://github.com/snguyenthanh/better_profanity","commit_stats":{"total_commits":90,"total_committers":9,"mean_commits":10.0,"dds":"0.37777777777777777","last_synced_commit":"b80ace7eb78addbdf7f625068e8a86f582d918c9"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snguyenthanh%2Fbetter_profanity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snguyenthanh%2Fbetter_profanity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snguyenthanh%2Fbetter_profanity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snguyenthanh%2Fbetter_profanity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snguyenthanh","download_url":"https://codeload.github.com/snguyenthanh/better_profanity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222670691,"owners_count":17020513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["censor","censored-words","censorship","leetspeak","profanity","python","words"],"created_at":"2024-08-01T05:02:13.707Z","updated_at":"2024-11-02T03:30:38.728Z","avatar_url":"https://github.com/snguyenthanh.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# better_profanity\n\n*Blazingly fast cleaning swear words (and their leetspeak) in strings*\n\n[![release](https://img.shields.io/badge/dynamic/json.svg?label=release\u0026url=https%3A%2F%2Fpypi.org%2Fpypi%2Fbetter-profanity%2Fjson\u0026query=%24.info.version\u0026colorB=blue)](https://github.com/snguyenthanh/better_profanity/releases/latest)\n[![Build Status](https://travis-ci.com/snguyenthanh/better_profanity.svg?branch=master)](https://travis-ci.com/snguyenthanh/better_profanity)\n![python](https://img.shields.io/badge/python-3-blue.svg)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=popout)](https://github.com/snguyenthanh/better_profanity/blob/master/LICENSE)\n\n\u003e Currently there is a [performance issue with the latest version (0.7.0)](https://github.com/snguyenthanh/better_profanity/issues/19). It is recommended to use the [last stable version 0.6.1](https://pypi.org/project/better-profanity/0.6.1/).\n\nInspired from package [profanity](https://github.com/ben174/profanity) of [Ben Friedland](https://github.com/ben174), this library is significantly faster than the original one, by using string comparison instead of regex.\n\nIt supports [modified spellings](https://en.wikipedia.org/wiki/Leet) (such as `p0rn`, `h4NDjob`, `handj0b` and `b*tCh`).\n\n## Requirements\n\nThis package works with `Python 3.5+` and `PyPy3`.\n\n## Installation\n\n```sh\npip3 install better_profanity\n```\n\n## Unicode characters\n\nOnly Unicode characters from categories `Ll`, `Lu`, `Mc` and `Mn` are added. More on Unicode categories can be found [here][unicode category link].\n\n[unicode category link]: https://en.wikipedia.org/wiki/Template:General_Category_(Unicode)\n\nNot all languages are supported yet, such as *Chinese*.\n\n## Usage\n\n```python\nfrom better_profanity import profanity\n\nif __name__ == \"__main__\":\n    profanity.load_censor_words()\n\n    text = \"You p1ec3 of sHit.\"\n    censored_text = profanity.censor(text)\n    print(censored_text)\n    # You **** of ****.\n```\n\nAll modified spellings of words in [profanity_wordlist.txt](./better_profanity/profanity_wordlist.txt) will be generated. For example, the word `handjob` would be loaded into:\n\n```python\n'handjob', 'handj*b', 'handj0b', 'handj@b', 'h@ndjob', 'h@ndj*b', 'h@ndj0b', 'h@ndj@b',\n'h*ndjob', 'h*ndj*b', 'h*ndj0b', 'h*ndj@b', 'h4ndjob', 'h4ndj*b', 'h4ndj0b', 'h4ndj@b'\n```\n\nThe full mapping of the library can be found in [profanity.py](./better_profanity/better_profanity.py#L18-L26).\n\n### 1. Censor swear words from a text\n\nBy default, `profanity` replaces each swear words with 4 asterisks `****`.\n\n```python\nfrom better_profanity import profanity\n\nif __name__ == \"__main__\":\n    text = \"You p1ec3 of sHit.\"\n\n    censored_text = profanity.censor(text)\n    print(censored_text)\n    # You **** of ****.\n```\n\n### 2. Censor doesn't care about word dividers\n\nThe function `.censor()` also hide words separated not just by an empty space ` ` but also other dividers, such as `_`, `,` and `.`. Except for `@, $, *, \", '`.\n\n```python\nfrom better_profanity import profanity\n\nif __name__ == \"__main__\":\n    text = \"...sh1t...hello_cat_fuck,,,,123\"\n\n    censored_text = profanity.censor(text)\n    print(censored_text)\n    # \"...****...hello_cat_****,,,,123\"\n```\n\n### 3. Censor swear words with custom character\n\n4 instances of the character in second parameter in `.censor()` will be used to replace the swear words.\n\n```python\nfrom better_profanity import profanity\n\nif __name__ == \"__main__\":\n    text = \"You p1ec3 of sHit.\"\n\n    censored_text = profanity.censor(text, '-')\n    print(censored_text)\n    # You ---- of ----.\n```\n\n### 4. Check if the string contains any swear words\n\nFunction `.contains_profanity()` return `True` if any words in the given string has a word existing in the wordlist.\n\n```python\nfrom better_profanity import profanity\n\nif __name__ == \"__main__\":\n    dirty_text = \"That l3sbi4n did a very good H4ndjob.\"\n\n    profanity.contains_profanity(dirty_text)\n    # True\n```\n\n### 5. Censor swear words with a custom wordlist\n\n#### 5.1. Wordlist as a `List`\n\nFunction `load_censor_words` takes a `List` of strings as censored words.\nThe provided list will replace the default wordlist.\n\n```python\nfrom better_profanity import profanity\n\nif __name__ == \"__main__\":\n    custom_badwords = ['happy', 'jolly', 'merry']\n    profanity.load_censor_words(custom_badwords)\n\n    print(profanity.contains_profanity(\"Have a merry day! :)\"))\n    # Have a **** day! :)\n```\n\n#### 5.2. Wordlist as a file\n\nFunction `load_censor_words_from_file takes a filename, which is a text file and each word is separated by lines.\n\n```python\nfrom better_profanity import profanity\n\nif __name__ == \"__main__\":\n    profanity.load_censor_words_from_file('/path/to/my/project/my_wordlist.txt')\n```\n\n### 6. Whitelist\n\nFunction `load_censor_words` and `load_censor_words_from_file` takes a keyword argument `whitelist_words` to ignore words in a wordlist.\n\nIt is best used when there are only a few words that you would like to ignore in the wordlist.\n\n```python\n# Use the default wordlist\nprofanity.load_censor_words(whitelist_words=['happy', 'merry'])\n\n# or with your custom words as a List\ncustom_badwords = ['happy', 'jolly', 'merry']\nprofanity.load_censor_words(custom_badwords, whitelist_words=['merry'])\n\n# or with your custom words as a text file\nprofanity.load_censor_words_from_file('/path/to/my/project/my_wordlist.txt', whitelist_words=['merry'])\n```\n\n### 7. Add more censor words\n\n```python\nfrom better_profanity import profanity\n\nif __name__ == \"__main__\":\n    custom_badwords = ['happy', 'jolly', 'merry']\n    profanity.add_censor_words(custom_badwords)\n\n    print(profanity.contains_profanity(\"Happy you, fuck!\"))\n    # **** you, ****!\n```\n\n## Limitations\n\n1. As the library compares each word by characters, the censor could easily be bypassed by adding any character(s) to the word:\n\n```python\nprofanity.censor('I just have sexx')\n# returns 'I just have sexx'\n\nprofanity.censor('jerkk off')\n# returns 'jerkk off'\n```\n\n2. Any word in [wordlist](https://github.com/snguyenthanh/better_profanity/blob/master/better_profanity/profanity_wordlist.txt) that have non-space separators cannot be recognised, such as `s \u0026 m`, and therefore, it won't be filtered out. This problem was raised in [#5](https://github.com/snguyenthanh/better_profanity/issues/5).\n\n## Testing\n\n```sh\npython3 tests.py\n```\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n\n## Special thanks to\n\n- [Andrew Grinevich](https://github.com/Derfirm) - Add support for Unicode characters.\n- [Jaclyn Brockschmidt](https://github.com/jcbrockschmidt) - Optimize string comparison.\n\n## Acknowledgments\n\n- [Ben Friedland](https://github.com/ben174) - For the inspiring package [profanity](https://github.com/ben174/profanity).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnguyenthanh%2Fbetter_profanity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnguyenthanh%2Fbetter_profanity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnguyenthanh%2Fbetter_profanity/lists"}