Registry / serialization / better-profanity

better-profanity

JSON →
library0.7.0pypypi✓ verified 25d ago

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-profanity
INSTALL
IMPORT
SIG · BETTER-PROFANITY
B
better-profanity
serializationpythonv0.7.0
Install
1.7s avg
Import
30ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.034s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.026s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

profanity
from better_profanity import profanity

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

from better_profanity import profanity # Load the default wordlist profanity.load_censor_words() text_with_profanity = "This is a f*cking example with some sh!t words." censored_text = profanity.replace_profanity(text_with_profanity) print(f"Original: {text_with_profanity}") print(f"Censored: {censored_text}") # Adding custom words (adds to the existing list) profanity.add_censor_words(['darn', 'heck']) custom_text = "Oh, darn, that was a heck of a game." censored_custom_text = profanity.replace_profanity(custom_text) print(f"Original (custom): {custom_text}") print(f"Censored (custom): {censored_custom_text}") # Check if profanity is present contains_profanity = profanity.contains_profanity("This sentence has a badword.") print(f"Contains profanity: {contains_profanity}")
Debug
Known issues
breakingIn 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.
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.
affects: 0.3.0 and later
gotchaCalling `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.
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.
affects: All versions
gotchaThe 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.
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.
affects: 0.3.4, 0.7.0 and later
gotchaThe `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.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'better_profanity'
The 'better-profanity' library has not been installed, or there is a typo in the import statement.
fix
Ensure the library is installed using pip, then use the correct import statement:
```python
pip install better-profanity
from better_profanity import profanity
```
FileNotFoundError: [Errno 2] No such file or directory: 'your_custom_wordlist.txt'
The specified file path for the custom wordlist in `load_censor_words_from_file()` does not exist or is incorrect.
fix
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')
```
TypeError: words must be of type str, list, or None
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.
fix
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'])
```
Upgrade
Version history
0.7.0latest on PyPI · released Nov 2, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
30 hits · last 30 days
node
28
OpenAI (training)
1
Resources
better-profanity — pip install better-profanity · libregistry