Skip to main content

A library using regex manipulation to detect and block profanity in strings.

Project description

No-Profanity

No-Profanity is a simple library that uses regexes to detect and block profanity in strings. It's designed to detect even the most creative modifications of profanity.

How to use?

The library contains 1 class. This class contains 5 functions.

from no_profanity import ProfanityFilter

# ProfanityFilter(censor_symbol: str = "*")
filter = ProfanityFilter()

# add_custom_words(words: list) -> None
filter.add_custom_words(["happy", "hello"])

# add_custom_wordlist(filepath: str) -> None
filter.add_custom_wordlist("./wordlist.txt")

# set_censor_symbol(censor_symbol: str) -> None
filter.set_censor_symbol("-")

# is_profanity(txt: str) -> bool
filter.is_profanity("my name is Lime") # False
filter.is_profanity("shut the fuck up") # True

# censor_text(txt: str, censor_symbol: str = None) -> str
filter.censor_text("what the fuck is this") # Output: what the ---- is this

# Without set_censor_symbol(): what the **** is this

# full_detection(txt: str) -> list[dict]
# [
#   {
#       string_match,
#       start,
#       end,
#       found_word
#   }, ...
# ]

filter.full_detection("you fuck1ng bitch") # [{'string_match': 'fuck1ng', 'start': 4, 'end': 11, 'found_word': 'fucking'}, {'string_match': 'bitch', 'start': 12, 'end': 17, 'found_word': 'bitch'}]

Pros

The library can detect modified profanity. Examples:

filter.is_profanity("fuckfuck") # True
filter.is_profanity("niggafuck") # True
filter.is_profanity("b i t c h") # True
filter.is_profanity("sexx") # True

filter.is_profanity("n1@@a") # True
filter.is_profanity("f u cckbitch es") # True

filter.is_profanity("@fuck@") # True

Cons

The filter can be bypassed by putting an extra letter(s) that isn't part of profanity. This will be fixed in the future! :D

filter.is_profanity("afuck") # False

This library has originally been made for my Discord bot AutoProtection, but now it's released for everyone to use! If you have more questions, please contact me on my Discord server.

Thank you for reading this! I hope you'll like my first library. I'm always opened to new ideas for improvements! ^^

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

no_profanity-1.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

no_profanity-1.1.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file no_profanity-1.1.1.tar.gz.

File metadata

  • Download URL: no_profanity-1.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for no_profanity-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ace1c7fd4595583606de9204bff27937d56f95ec2beea331afe944627a8a78ee
MD5 18dac434f860800293c9da101a79eb15
BLAKE2b-256 7784684905d5d8aa691a161a288688e04f29210041032b7b1b2ec579f1577721

See more details on using hashes here.

File details

Details for the file no_profanity-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: no_profanity-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for no_profanity-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7dd057c037c6b134f883d7f3144d238c4a9159358d6dd844271ad9da006525e
MD5 1c64579f76eda62d77e49c6398f4eaf2
BLAKE2b-256 bc43499ad8d3d223ca5309dea541ff42aceff509ab03799cdd03bdab87df1edb

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