Metadata-Version: 2.4
Name: wordfilter2
Version: 1.2.0
Summary: A simple word filter module for Python
Home-page: https://github.com/VariableIsUndefined/wordfilter2
Author: VariableIsUndefined
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Communications
Classifier: Topic :: Text Processing :: Linguistic
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 5 - Production/Stable
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: requests
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# WordFilter2

A powerful and customizable library for filtering profanity in Python.

[![PyPI version](https://img.shields.io/pypi/v/wordfilter2)](https://pypi.org/project/wordfilter2/) 

## Features

-----
- Case-insensitive filtering
- Full or partial matching
- Custom replacement functions
- Load from local file or URL
- Supports multiple formats (txt, json)
- Normalize spaces in filtered output
- Optional duplicate word detection
- Find matched words in text
- Configurable timeout and size limits for remote files

## Installation

-----

```bash
pip install wordfilter2
```

## Usage

-----

```python
from wordfilter2 import WordFilter

# Initialize the filter
wf = WordFilter(ignore_case=True, partial_match=False, replace_with="*")

# Add words to filter
wf.add_words(["badword", "offensive"])

# Filter text
filtered = wf.filter("This is a badword example.")
print(filtered)  # Output: This is a ******* example.
```

## Custom Replacement

-----

```python
from wordfilter2 import WordFilter

def censor(word: str) -> str:
    return "[" + word.upper() + "]"

wf = WordFilter(replace_with_func=censor)
wf.add_word("spoiler")
print(wf.filter("This is a spoiler."))  # Output: This is a [SPOILER].
```

or you can use built-in utils:

```python
from wordfilter2 import WordFilter
from wordfilter2.utils import (mask_full, mask_partial, mask_first_last,
                               mask_censor, mask_custom)

wf = WordFilter(replace_with_func=mask_partial("#"))
wf.add_word("spoiler")

print(wf.filter("This is a spoiler."))  # Output: This is a s#####r.
```

## Options

-----

```python
# Optional parameters:
wf = WordFilter(
    ignore_case=True,
    partial_match=True,
    replace_with="*",
    replace_with_func=None,
    normalize_spaces=True
)
```

## Check for Profanity

-----

```python
# Check if text contains profanity
contains = wf.contains_profanity("Something offensive here.")
print(contains)  # Output: True
```

## Working with Files

-----

```python
# Load words from a .txt or .json file (one word per line)
wf.load_from_file("banned_words.txt")

# Load words from URL with timeout and size limit
wf.load_from_url("https://your_url/goes_here.json",  timeout=5, max_size=1024 * 1024)

# Save the current word list
wf.save_to_file("output_words.txt")
```

## License

-----

This project is licensed under the MIT License.
See [LICENSE](https://github.com/VariableIsUndefined/wordfilter2/blob/master/LICENSE.md) for details.


-----

> Clean content made simple with **wordfilter2**.
