{"id":2884,"library":"better-profanity","title":"Better Profanity","description":"Better Profanity is a blazingly fast Python library for cleaning swear words and their leetspeak variations from strings. It provides an efficient way to detect and replace offensive language using a pre-loaded or custom wordlist. The library is actively maintained, with the current version being 0.7.0, and receives regular updates for performance and wordlist improvements.","status":"active","version":"0.7.0","language":"python","source_language":"en","source_url":"https://github.com/snguyenthanh/better_profanity","tags":["profanity","censor","text-processing","nlp"],"install":[{"cmd":"pip install better-profanity","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"profanity","correct":"from better_profanity import profanity"}],"quickstart":{"code":"from better_profanity import profanity\n\n# Load the default wordlist\nprofanity.load_censor_words()\n\ntext_with_profanity = \"This is a f*cking example with some sh!t words.\"\ncensored_text = profanity.replace_profanity(text_with_profanity)\nprint(f\"Original: {text_with_profanity}\")\nprint(f\"Censored: {censored_text}\")\n\n# Adding custom words (adds to the existing list)\nprofanity.add_censor_words(['darn', 'heck'])\ncustom_text = \"Oh, darn, that was a heck of a game.\"\ncensored_custom_text = profanity.replace_profanity(custom_text)\nprint(f\"Original (custom): {custom_text}\")\nprint(f\"Censored (custom): {censored_custom_text}\")\n\n# Check if profanity is present\ncontains_profanity = profanity.contains_profanity(\"This sentence has a badword.\")\nprint(f\"Contains profanity: {contains_profanity}\")\n","lang":"python","description":"Initialize the profanity filter by loading the default wordlist, then use `replace_profanity` to clean strings. You can add custom words with `add_censor_words` or check for profanity with `contains_profanity`."},"warnings":[{"fix":"If your application relies on detection patterns involving '&' or '^' as dividers, you may need to implement custom logic or load a modified wordlist to explicitly include these patterns.","message":"In version 0.3.0, the characters '&' and '^' were removed from the list of default word dividers. This means that leetspeak or disguised profanity using these characters (e.g., 'f&ck') might no longer be detected as profanity unless explicitly added to a custom wordlist or separated by other dividers.","severity":"breaking","affected_versions":"0.3.0 and later"},{"fix":"Use `profanity.add_censor_words(['new_word'])` to extend the current list. Only use `load_censor_words()` when you intend to completely reset the profanity list.","message":"Calling `profanity.load_censor_words()` (or `load_censor_words_from_file()`) will *replace* the entire active wordlist by default, not append to it. If you wish to add words to an existing wordlist, use `profanity.add_censor_words()` instead.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Regularly review your profanity filtering results after upgrading the library. If precise control over the wordlist is required, consider using `profanity.load_censor_words_from_file()` with your own curated wordlist.","message":"The default wordlist has been significantly updated in versions 0.3.4 and 0.7.0. This means that profanity detection behavior can change for applications simply by upgrading the library, potentially detecting more words or different leetspeak variations, even without any code changes.","severity":"gotcha","affected_versions":"0.3.4, 0.7.0 and later"},{"fix":"Ensure your project runs on a stable and commonly supported Python 3.x version. While `==3.*` is broad, it's best to test thoroughly if targeting very old or very new Python 3.x environments.","message":"The `requires_python` specifier on PyPI is `==3.*`, meaning the library officially supports any Python 3.x version (e.g., 3.0, 3.1, ..., 3.12), but explicitly *not* Python 4.x or later. Historically, there have also been specific compatibility fixes for Python 3.5, suggesting subtle issues might arise with less common or very old 3.x releases.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.7.0':50 'activ':43 'better':1,3 'blaze':7 'censor':61 'clean':12 'current':47 'custom':38 'detect':27 'effici':24 'fast':8 'improv':59 'languag':31 'leetspeak':17 'librari':10,41 'load':36 'maintain':44 'nlp':65 'offens':30 'perform':56 'pre':35 'pre-load':34 'process':64 'profan':2,4,60 'provid':22 'python':9 'receiv':52 'regular':53 'replac':29 'string':20 'swear':13 'text':63 'text-process':62 'updat':54 'use':32 'variat':18 'version':48 'way':25 'word':14 'wordlist':39,58","created_at":"2026-04-11T09:11:45.089545+00:00","updated_at":"2026-04-16T00:07:15.195789+00:00","problems":[{"fix":"Ensure the library is installed using pip, then use the correct import statement:\n```python\npip install better-profanity\nfrom better_profanity import profanity\n```","cause":"The 'better-profanity' library has not been installed, or there is a typo in the import statement.","error":"ModuleNotFoundError: No module named 'better_profanity'"},{"fix":"Verify that the file path to 'your_custom_wordlist.txt' is correct and that the file exists at that location.\n```python\nfrom better_profanity import profanity\n# Ensure 'path/to/your_custom_wordlist.txt' is the correct and accessible path\nprofanity.load_censor_words_from_file('path/to/your_custom_wordlist.txt')\n```","cause":"The specified file path for the custom wordlist in `load_censor_words_from_file()` does not exist or is incorrect.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'your_custom_wordlist.txt'"},{"fix":"Provide a list of strings, a string representing a file path, or `None` as the argument for custom words.\n```python\nfrom better_profanity import profanity\n\n# Fix for load_censor_words with a list\ncustom_badwords = ['badword1', 'badword2']\nprofanity.load_censor_words(custom_badwords)\n\n# Fix for initializing Profanity directly with a list\n# from better_profanity import Profanity\n# profanity = Profanity(words=['badword1', 'badword2'])\n```","cause":"When initializing `Profanity` or calling `load_censor_words`, an invalid data type (e.g., an integer or a dictionary) was provided for the `words` or `custom_words` argument.","error":"TypeError: words must be of type str, list, or None"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.7.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/snguyenthanh/better_profanity","docs":null,"changelog":null,"pypi":"https://pypi.org/project/better-profanity/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}