Introduction
no-nepali-profanity is a small, dependency-free profanity filter for Python. It detects and censors profanity in English, Romanized Nepali and Devanagari Nepali, plus the Hindi slang common in Nepal.
py
from no_nepali_profanity import censor, check, contains_profanity, find_profanity
contains_profanity("Great teacher!") # False
contains_profanity("मुजीको क्लास") # True
find_profanity("f.u.c.k this sh1t") # ["fuck", "shit"]
censor("you muji") # "you ****"
check("you muji").censor() # "you ****"Why another profanity filter?
General-purpose profanity filters are built for English. On a Nepali site they fail in two ways:
- They miss Nepali. People write Nepali in Devanagari (
मुजी) and in Latin letters (muji,mujiko), often in the same sentence as English. An English word list catches neither. - They block real names. Substring matching flags names like Shitij or Randip. On a site where people sign up with their real names, that is a worse failure than a missed swear.
This package is built for that situation: it matches whole words, understands Nepali postpositions, and checks its word lists against common Nepali names.
Features
- Three scripts in one pass. English, Romanized Nepali and Devanagari, including mixed text.
- Handles common dodges. Leetspeak (
sh1t,@ss),!fori(sh!t),*for a hidden letter (f*ck), stretched letters (fuuuuck) and spelled-out letters (f.u.c.k,f u c k). - Understands Nepali grammar. Postpositions and plurals like
-ko,-laiand-haru(mujiko,मुजीहरू). - Handles Devanagari spelling variants. Nukta, chandrabindu vs anusvara, and zero-width joiners.
- Censors in place. Masks exactly what the user typed, even
F.U.C.KorSh1t, and leaves the rest alone. - Catches phrases. Word pairs that are only offensive together, like
sasto manche. - Configurable. Turn each language on or off, and pick one of three strictness levels.
- The same in every language. JavaScript, Python, Go, PHP and Dart share the word lists and matching rules, and are tested against the same inputs, so a comment gets the same result on every part of your stack.
- Zero dependencies. Pure Python, standard library only, with type hints (
py.typed).
What it isn't
- It doesn't understand meaning. Insults without a listed word, sarcasm and context are out of scope. Treat it as a first-pass filter, and send anything that matters to a human moderator.