Email phishing and spam detection library with built-in REST API
Project description
phishdetect
Email phishing and spam detection library — drop it into any Python project or run it as a standalone REST API on your mail server.
Install
pip install phishdetect
Use as a Python library
from phishdetect import PhishingDetector
detector = PhishingDetector()
result = detector.analyze({
"sender": "support@paypa1.com",
"subject": "Urgent: verify your account NOW!!",
"content": "Click here to reset your password immediately.",
"reply_to": "", # optional
})
print(result["risk_score"]) # "HIGH", "MEDIUM", or "LOW"
print(result["risk_level"]) # 0–100 numeric score
print(result["warnings"]) # detailed list of every signal found
Integrate with your mail server
from phishdetect import PhishingDetector
detector = PhishingDetector()
def on_email_received(email):
result = detector.analyze({
"sender": email.from_address,
"subject": email.subject,
"content": email.body,
})
if result["risk_score"] == "HIGH":
quarantine(email)
elif result["risk_score"] == "MEDIUM":
add_warning_banner(email)
else:
deliver(email)
Run as a REST API server
phishdetect-server
# Server starts at http://0.0.0.0:5000
API endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /analyze | Analyze an email for phishing |
| GET | /health | Health check |
| GET | /status | Domain intelligence database info |
| POST | /update | Refresh the Tranco domain list |
Example API call
curl -X POST http://localhost:5000/analyze \
-H "Content-Type: application/json" \
-d '{
"sender": "support@paypa1.com",
"subject": "Urgent: verify your account",
"content": "Click here to reset your password."
}'
What it detects
- Lookalike domains —
paypa1.comvspaypal.com(Levenshtein distance) - Homoglyph attacks — Unicode characters that look like Latin letters (е, о, а)
- Subdomain abuse —
paypal.attacker.compretending to be PayPal - Suspicious keywords — urgency, financial fraud, prize/lottery patterns
- Deceptive links — visible URL differs from actual href destination
- Reply-To mismatch — replies routed to a different domain
- New domains — recently registered domains flagged via WHOIS
- Spam signals — ALL CAPS subjects, excessive exclamation marks, bulk patterns
How the domain database works
On first run, phishdetect automatically downloads the Tranco top-1M domain list and stores the top 50,000 domains in a local SQLite database at ~/.phishdetect/phishing.db. This refreshes weekly. No API key required.
License
MIT
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 phishguard-1.0.1.tar.gz.
File metadata
- Download URL: phishguard-1.0.1.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6423758e22f49c6d714b30f6332f0b20bc633e30b19d57eddcab8264b56d1272
|
|
| MD5 |
f74dd4404a4711b7c8141ec7a5f562f1
|
|
| BLAKE2b-256 |
3ee240c4816c8af59ddc6d360334be3b75ee2e5f485475ec9f6530e9ee8826da
|
File details
Details for the file phishguard-1.0.1-py3-none-any.whl.
File metadata
- Download URL: phishguard-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9357957dc0cd075834deb2fe75eb86ac5aff296aa5a3465e65efde35ad5ed50
|
|
| MD5 |
f4c9e31943a1f2020e715243059732d6
|
|
| BLAKE2b-256 |
5762e2c07c53cf647ca430854de2508d58f4df3003ebaa5474df96d65b95b946
|