GLIN PROFANITY - Python
ML-Powered Profanity Detection for the Modern Web
Installation
pip install glin-profanity
Quick Start
from glin_profanity import Filter
filter = Filter()
if filter.is_profane("This is a damn example"):
print("Profanity detected!")
result = filter.check_profanity("This is a damn example")
print(result["profane_words"])
print(result["contains_profanity"])
Configuration
from glin_profanity import Filter, SeverityLevel
filter = Filter({
"languages": ["english", "spanish"],
"case_sensitive": False,
"word_boundaries": True,
"replace_with": "***",
"severity_levels": True,
"custom_words": ["badword"],
"ignore_words": ["exception"],
"allow_obfuscated_match": True,
"fuzzy_tolerance_level": 0.8,
})
result = filter.check_profanity("bad content here")
Features
| Multi-language | 24 languages supported |
| Context-aware | Reduces false positives |
| Configurable | Custom word lists, severity levels |
| High performance | Optimized for speed |
| TypeScript parity | Same API as JS package |
API Reference
Filter Class
class Filter:
def __init__(self, config: Optional[FilterConfig] = None)
def is_profane(self, text: str) -> bool
def check_profanity(self, text: str) -> CheckProfanityResult
def matches(self, word: str) -> bool
def check_profanity_with_min_severity(self, text: str, min_severity: SeverityLevel) -> dict
Return Type
{
"contains_profanity": bool,
"profane_words": List[str],
"processed_text": Optional[str],
"severity_map": Optional[Dict],
"matches": Optional[List[Match]],
"context_score": Optional[float],
"reason": Optional[str]
}
SeverityLevel
SeverityLevel.EXACT
SeverityLevel.FUZZY
Supported Languages
24 languages: Arabic, Chinese, Czech, Danish, Dutch, English, Esperanto, Finnish, French, German, Hindi, Hungarian, Italian, Japanese, Korean, Norwegian, Persian, Polish, Portuguese, Russian, Spanish, Swedish, Thai, Turkish
Documentation
Development
git clone https://github.com/GLINCKER/glin-profanity
cd glin-profanity/packages/py
pip install -e ".[dev]"
pytest
pytest --cov=glin_profanity
black glin_profanity tests
isort glin_profanity tests
mypy glin_profanity
ruff check glin_profanity tests
License
MIT License - see LICENSE