I Built a Simple Email Spam Detector in Python — It Actually Works
A lightweight Python script that detects spam emails based on keyword scoring and probability calculation — fully open-source and customizable.
PROJECT
Abhinav
6/17/20251 min read
Lately, I’ve been diving into how spam filters work, and I thought — why not build a basic one myself? So I made a lightweight Email Spam Detector using just Python. No heavy libraries, no overkill machine learning models. Just logic, NumPy, and a bit of math.
The idea is simple: it checks for certain keywords like “free”, “win”, “money” — stuff you’d usually find in spam — and gives each one a weight. Then it calculates a spam score using dot product and passes it through a sigmoid function to get a clean probability between 0 and 1.
And yes, it works. Short emails like
“You’ve won a free prize! Click now!”
get flagged, while regular messages like
“Please review the attached report before tomorrow’s meeting”
are marked clean.




If you’re curious, I’ve pushed the full code here:
GitHub Repo — spam-detector
It's super readable and easy to tweak. You can:
Change or add keyword weights
Adjust the spam threshold
Test your own emails right in the script
Again, if you're into building small, real-world Python projects, you can check out the code on GitHub:
github.com/abhinav25232354/spam-detector
Let me know what you think, or fork it and build on top of it.