Skip to main content

Glin-Profanity is a lightweight and efficient Python package designed to detect and filter profane language in text inputs across multiple languages.

Project description

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

# Basic usage
filter_instance = Filter()

# Check if text contains profanity
if filter_instance.is_profane("This is a damn example"):
    print("Profanity detected!")

# Get detailed results
result = filter_instance.check_profanity("This is a damn example")
print(result["profane_words"])  # ['damn']
print(result["contains_profanity"])  # True

Configuration Options

from glin_profanity import Filter, SeverityLevel

# Advanced configuration
config = {
    "languages": ["english", "spanish"],  # Specific languages
    "case_sensitive": False,              # Case sensitivity
    "word_boundaries": True,              # Enforce word boundaries
    "replace_with": "***",                # Replacement text
    "severity_levels": True,              # Enable severity detection
    "custom_words": ["badword"],          # Add custom words
    "ignore_words": ["exception"],        # Ignore specific words
    "allow_obfuscated_match": True,       # Detect obfuscated text
    "fuzzy_tolerance_level": 0.8,         # Fuzzy matching threshold
}

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],      # If replace_with is set
    "severity_map": Optional[Dict],       # If severity_levels is True
    "matches": Optional[List[Match]],     # Detailed match information
    "context_score": Optional[float],     # Context analysis score
    "reason": Optional[str]               # Analysis reason
}

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

# Clone the repository
git clone https://github.com/GLINCKER/glin-profanity
cd glin-profanity/packages/py

# Install with development dependencies
pip install -e ".[dev]"

Testing

# Run tests
pytest

# Run tests with coverage
pytest --cov=glin_profanity

Code Quality

# Format code
black glin_profanity tests

# Sort imports
isort glin_profanity tests

# Type checking
mypy glin_profanity

# Linting
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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glin_profanity-2.2.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glin_profanity-2.2.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file glin_profanity-2.2.0.tar.gz.

File metadata

  • Download URL: glin_profanity-2.2.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for glin_profanity-2.2.0.tar.gz
Algorithm Hash digest
SHA256 06ff9b33fe3a505f203f17d6cb0f1c152e8ca949d87fb7f29b8a6551daefceb9
MD5 4af8a00c74eb27a0443fbbe12101aa36
BLAKE2b-256 7b008ebe664cf28fa2d45825d94e6fa384e809045571ee632d48f53510ac3321

See more details on using hashes here.

File details

Details for the file glin_profanity-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for glin_profanity-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d2a7a43006dfa8bc4d8b45fe1e852c8028f7e465328d2eac147163e30ffad55
MD5 d31d1f16fc434e4ce444a609b07a671a
BLAKE2b-256 f53cb63dadb9f6e582299b7d5174947364f020c17efff3b6f114a0c76bea1954

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page