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.
pip install better-profanityVerified import paths — ran on the pinned version, not inferred.
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`.
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.
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.
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.
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.
Ensure the library is installed using pip, then use the correct import statement: ```python pip install better-profanity from better_profanity import profanity ```
Verify that the file path to 'your_custom_wordlist.txt' is correct and that the file exists at that location.
```python
from better_profanity import profanity
# Ensure 'path/to/your_custom_wordlist.txt' is the correct and accessible path
profanity.load_censor_words_from_file('path/to/your_custom_wordlist.txt')
```Provide a list of strings, a string representing a file path, or `None` as the argument for custom words. ```python from better_profanity import profanity # Fix for load_censor_words with a list custom_badwords = ['badword1', 'badword2'] profanity.load_censor_words(custom_badwords) # Fix for initializing Profanity directly with a list # from better_profanity import Profanity # profanity = Profanity(words=['badword1', 'badword2']) ```
No dependency data recorded yet.