Skip to main content

prof4nities

A small Python library to detect and optionally censor profane or inappropriate words using language-specific wordlists, Levenshtein distance, and fuzzy string matching.

Installation

To install using pip, run:

pip install prof4nities

Quick example

from prof4nities import Censor

censor = Censor(language="en")

# assuming "badword" is in the wordlist
print(censor("badword in a sentence"))
# >>> ******* in a sentence

print(censor(["badword", "in", "a", "sentence"]))
# >>> ******* in a sentence

print(censor(["badword", "in", "a", "sentence"], stringify=False))
# >>> [Word('badword'), Word('in'), Word('a'), Word('sentence')]

The Censor class loads a language-specific Wordlist (default en) and exposes a callable interface. See prof4nities/filter.py for implementation details.

Configuration via environment variables

prof4nities reads a couple of runtime thresholds from environment variables (defined in prof4nities/config.py). Export them before running your code to change behavior:

export LEVENSHTEIN_THRESHOLD=0.75
export FUZZY_RATIO_THRESHOLD=0.85
# then run your script or REPL
python -c "from prof4nities import Censor; print(Censor('en')('badword'))"

Defaults are:

  • LEVENSHTEIN_THRESHOLD=0.8
  • FUZZY_RATIO_THRESHOLD=0.8

Persistent cache

Two kinds of persisted data are used by the library to avoid repeated downloads:

  • WordNet corpora: Censor downloads the NLTK WordNet corpus on first use and stores it in the platform cache directory returned by prof4nities.config.Directories.CACHE_DIR.
  • Wordlists: fetched profanity wordlists are cached under the same application cache in the wordlists/ subdirectory (e.g. <cache_dir>/wordlists/en.txt). The Wordlist manager will use a cached copy when present and otherwise fetch from the upstream source and write a best-effort cache copy.

The exact cache location depends on the platform (see the platformdirs package). To inspect or override the cache location at runtime you can set the typical platform environment variables (for example on Linux set XDG_CACHE_HOME) or read the path via the prof4nities.config.Directories.CACHE_DIR value in code.

Development

Setting up

Install uv using pip.

pip install uv

Other installation methods are documented here.

Structure

prof4nities/
├── censor.py          # Core Censor behavior and docstring examples
├── config.py          # Environment-driven settings
└── manager/
    └── wordlist.py    # Wordlist fetching and processing

Testing

Pytest is used for testing. To run unit tests, run:

uv run pytest tests/

To make your own test, make a file prefixed with test_ and put it inside the tests/ directory and should be arranged accordingly.

Then within the file simply import the functionality to test

import pytest

from prof4nities import Censor


# Test cases should be prefixed with `test_`
def test_censor():
    ...
    assert True is True
    ...

Metadata

Release files for prof4nities 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prof4nities 0.1.1
File Size Uploaded Provenance
prof4nities-0.1.1.tar.gz 16.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for prof4nities 0.1.1
File Interpreter ABI Platform
prof4nities-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 36.4 kB

Release files / prof4nities-0.1.1.tar.gz

Download URL prof4nities-0.1.1.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e0871416d14bfced729f65a75b952a526edf64dedf4fdf0d3a187c9b932be841
BLAKE2b-256 checksum
How to use checksums
5c6bd056f127f8bb274b93b6b52e6d3591b57e2a645965fa04eb948a2b19e57f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.15

Release files / prof4nities-0.1.1-py3-none-any.whl

Download URL prof4nities-0.1.1-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ba08b7d18b542993f17654fbf54cc4088972f2790c2b6179ee69e793bf722a2
BLAKE2b-256 checksum
How to use checksums
eeef6ff6de60acd0418099e0ff1b0847662a0a632b92fc740e53c410e9feb597
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.15

Security for prof4nities 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page