{"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":"en","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,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}