Python port of the Obscenity profanity filtering library
Project description
pyobscenity
A Python port of the JavaScript library obscenity for detecting and censoring obscene words in text.
Note: Due to the nature of this library, repository contents may be considered NSFW or offensive.
Features
- Simple API - Censor profanity with a single function call
- Multiple censoring strategies - Full replacement, keep start/end, grawlix, fixed, random
- Smart detection - Handles case variations, leet speak, Unicode lookalikes
- Language support - Built-in English preset with 100+ phrases
- Whitelist support - Exclude specific terms from censoring
- Reusable filters - Build efficient, reusable filters for batch processing
Quick Start
Installation
pip install pyobscenity
Basic Usage
from pyobscenity import censor, check, find_matches
# Censor profanity
result = censor("This is fucking great!")
# "This is ****ing great!"
# Check if text contains profanity
if check(user_input):
print("Please keep it clean!")
# Find all profanity matches
matches = find_matches("fuck this shit")
for match in matches:
print(f"'{match.matched_text}' at position {match.start_index}")
Note: the default English filters are too aggressive for some use cases. Consider customizing the dataset or transformers for your needs. It is based on the original filter from the JavaScript library, with some minor adjustments.
Common Use Cases
Censor with Different Styles
from pyobscenity import censor
# Default (full replacement with *)
censor("This is shit")
# "This is ****"
# Custom character
censor("shit", censor_char="#")
# "####"
# Keep first character as hint
censor("shit", censor_type="keep_start", keep_length=1)
# "s***"
# Fixed replacement
censor("shit", censor_type="fixed", replacement="[REDACTED]")
# "[REDACTED]"
# Grawlix (comic book style)
censor("shit", censor_type="grawlix")
# "@#$%"
Check and Find Matches
from pyobscenity import check, find_matches
# Simple check
has_profanity = check("hello world") # False
has_profanity = check("hello shit") # True
# Get match details
matches = find_matches("fuck this shit")
for m in matches:
print(f"'{m.matched_text}' at [{m.start_index}:{m.end_index}]")
Custom Datasets
from pyobscenity import Dataset, ProfanityFilter
# Define custom profanity
dataset = (
Dataset()
.add_phrase(lambda p: p
.add_pattern("|badword|")
.add_whitelisted_term("badwords") # Don't censor this
)
.add_phrase(lambda p: p.add_pattern("|naughty|"))
)
filter = ProfanityFilter.custom(dataset)
result = filter.censor("This is a badword") # Censored
result = filter.censor("These are badwords") # Not censored
What Gets Detected?
The library detects:
- Case variations:
shit,SHIT,Shit - Leet speak:
sh1t,5h1t - Unicode lookalikes:
shiт(with Cyrillic т)
These work automatically with the default English preset through intelligent text transformers.
Advanced features:
See ADVANCED_USAGE.md for:
- Custom censoring strategies and transformers
- Building domain-specific datasets
- Low-level API access
- Performance tuning
- Architecture details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyobscenity-0.1.0.tar.gz.
File metadata
- Download URL: pyobscenity-0.1.0.tar.gz
- Upload date:
- Size: 35.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fb3d3fd12c38d06ec501b145f0b4ad6c99affb3419ddf5129ea0db727def970
|
|
| MD5 |
04a74f8c52115b1c3ef472c27c91f005
|
|
| BLAKE2b-256 |
93c3bddadb23bfaebfe2c86ac6104f0fe47b659c408c6b009eccc7b88abdc0bb
|
Provenance
The following attestation bundles were made for pyobscenity-0.1.0.tar.gz:
Publisher:
python-publish.yml on gsteinLTU/pyobscenity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyobscenity-0.1.0.tar.gz -
Subject digest:
4fb3d3fd12c38d06ec501b145f0b4ad6c99affb3419ddf5129ea0db727def970 - Sigstore transparency entry: 829377755
- Sigstore integration time:
-
Permalink:
gsteinLTU/pyobscenity@0edf552cd4eccb07449819ebfeae4e64ff454305 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gsteinLTU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0edf552cd4eccb07449819ebfeae4e64ff454305 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyobscenity-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyobscenity-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c88293e625eface0e0efc75989f3d5a873d00b7ee8ed95693c52148702846d0
|
|
| MD5 |
6d651285c6a7f2c8c8ed29e1bb61f7b0
|
|
| BLAKE2b-256 |
52515ed2d6d988a7ece27de804e86a5c453f2efd64ceb23c8d908511fb00ae17
|
Provenance
The following attestation bundles were made for pyobscenity-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on gsteinLTU/pyobscenity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyobscenity-0.1.0-py3-none-any.whl -
Subject digest:
0c88293e625eface0e0efc75989f3d5a873d00b7ee8ed95693c52148702846d0 - Sigstore transparency entry: 829377774
- Sigstore integration time:
-
Permalink:
gsteinLTU/pyobscenity@0edf552cd4eccb07449819ebfeae4e64ff454305 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gsteinLTU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0edf552cd4eccb07449819ebfeae4e64ff454305 -
Trigger Event:
release
-
Statement type: