Glin-Profanity Python Package
A lightweight and efficient Python package designed to detect and filter profane language in text inputs across multiple languages.
Features
- 🌍 Multi-language Support: Supports 25+ languages including English, Spanish, French, German, Arabic, Chinese, and many more
- 🎯 Context-Aware Filtering: Advanced context analysis to reduce false positives
- ⚙️ Highly Configurable: Customize word lists, severity levels, and filtering behavior
- 🚀 High Performance: Optimized for speed and efficiency
- 🔧 Easy Integration: Simple API that works with any Python application
- 📝 TypeScript Compatible: Mirrors the API of the TypeScript version
Installation
pip install glin-profanity
Quick Start
from glin_profanity import Filter
filter_instance = Filter()
if filter_instance.is_profane("This is a damn example"):
print("Profanity detected!")
result = filter_instance.check_profanity("This is a damn example")
print(result["profane_words"])
print(result["contains_profanity"])
Configuration Options
from glin_profanity import Filter, SeverityLevel
config = {
"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,
}
filter_instance = Filter(config)
API Reference
Filter Class
__init__(config: Optional[FilterConfig] = None)
Initialize the filter with optional configuration.
is_profane(text: str) -> bool
Check if text contains profanity. Returns True if profanity is detected.
check_profanity(text: str) -> CheckProfanityResult
Perform comprehensive profanity analysis with detailed results.
matches(word: str) -> bool
Check if a single word matches profanity patterns. Alias for is_profane().
check_profanity_with_min_severity(text: str, min_severity: SeverityLevel) -> Dict
Check profanity with minimum severity filtering.
Types
CheckProfanityResult
{
"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: Exact word match
SeverityLevel.FUZZY: Fuzzy/approximate match
Supported Languages
Arabic, Chinese, Czech, Danish, English, Esperanto, Finnish, French, German, Hindi, Hungarian, Italian, Japanese, Korean, Norwegian, Persian, Polish, Portuguese, Russian, Spanish, Swedish, Thai, Turkish
Development
Setup
git clone https://github.com/GLINCKER/glin-profanity
cd glin-profanity/packages/py
pip install -e ".[dev]"
Testing
pytest
pytest --cov=glin_profanity
Code Quality
black glin_profanity tests
isort glin_profanity tests
mypy glin_profanity
ruff check glin_profanity tests
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
Support
Changelog
See CHANGELOG.md for a list of changes and updates.