Skip to main content

NSFWPY 🔥 (nsfwpy-onnx)

PyPI Version GitHub Repo Python Version License Hugging Face

High-performance, CPU-optimized Python 3.14 port of NSFWJS using ONNX Runtime.

Classify static images (JPEG, PNG, WEBP) and Animated WebP / GIF / APNG formats into 5 canonical NSFW categories (Drawing, Hentai, Neutral, Porn, Sexy).


🌟 Key Features

  • 🐍 Python 3.14 Native: Fully compatible with Python 3.10+ and Python 3.14.
  • 🎞️ Animated WebP & GIF Support: Keyframe sampling and frame-aggregated safety classification for Animated WebP, GIF, and APNG formats.
  • CPU Optimized: Powered by onnxruntime tuned for multi-threaded CPU execution with graph optimization.
  • 📦 HuggingFace Auto-Download: Automatically downloads missing ONNX models from Hugging Face (expertskb/nsfwpy).
  • 🪶 Ultra Lightweight: Minimal dependencies (numpy, pillow, onnxruntime, click). No heavy web servers required.
  • 🛠️ CLI Tool Included: Classify images directly from your terminal.

📥 Installation

Install directly from PyPI:

pip install nsfwpy-onnx

Or install from GitHub:

git clone https://github.com/expertskb/nsfwpy-onnx.git
cd nsfwpy-onnx
python3.14 -m venv .venv
source .venv/bin/activate
pip install -e .

🚀 Quick Usage

1. Python Library Usage

import nsfwpy

# Load model (auto-downloads from HuggingFace if missing)
model = nsfwpy.load_model("mobilenet_v2")

# Classify static image or animated WebP / GIF URL
results = model.classify("https://example.com/animation.webp", top_k=5)
print(results)
# Output:
# [
#   {'className': 'Neutral', 'probability': 0.6280},
#   {'className': 'Drawing', 'probability': 0.2822},
#   {'className': 'Sexy', 'probability': 0.0548},
#   {'className': 'Porn', 'probability': 0.0246},
#   {'className': 'Hentai', 'probability': 0.0104}
# ]

# Batch image classification
batch_results = model.classify_batch(["img1.jpg", "anim2.gif"])

2. Command Line Interface (CLI)

# Classify a local image file or URL
nsfwpy classify path/to/image.jpg

# Output formatted JSON
nsfwpy classify https://example.com/animation.webp --json-out

# Choose a specific model architecture
nsfwpy classify sample.jpg --model inception_v3

🧠 Supported Models

Model Name Backbone Accuracy Size Auto-Download Link
mobilenet_v2 (Default) MobileNet V2 Fast ~14 MB HF Download
mobilenet_v3 MobileNet V3 Balanced ~22 MB HF Download
inception_v3 Inception V3 High Precision ~95 MB HF Download

📂 Example Scripts Index

Professional production-ready scripts are included under examples/:

Run any example using:

python examples/06_animated_webp_gif_classification.py

📜 License

MIT License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nsfwpy_onnx-1.0.4.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

nsfwpy_onnx-1.0.4-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file nsfwpy_onnx-1.0.4.tar.gz.

File metadata

  • Download URL: nsfwpy_onnx-1.0.4.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for nsfwpy_onnx-1.0.4.tar.gz
Algorithm Hash digest
SHA256 fb0e2a1113c677ba67efe348a2d89b2e6ba204e2b5a8136a302380ea1a5dbc86
MD5 10159a1151902f74721e3f5afc4cf424
BLAKE2b-256 c150fc1c2a6817134bc535d9df1081b54e5c9b14d8a5bd30695d97e583dd8b37

See more details on using hashes here.

File details

Details for the file nsfwpy_onnx-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: nsfwpy_onnx-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for nsfwpy_onnx-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f1a74585970a3505e72f6c1c60571522f2722563fa475fb16c7c014e8a062dc5
MD5 310612efe185c7e907499306768fc24a
BLAKE2b-256 3c24b7df2b0f004779341205d76b5a9c7cb46862c818743a60ff2c0301845f5e

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

This release

1.0.4 This release

2 files

1.0.2

2 files

1.0.1

2 files

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