A fast, cached Python library to detect and block spam URL shortener domains.
Project description
Antispam Link Shorteners 🛡️
A lightweight, zero-dependency, ultra-fast Python library designed to detect and block malicious or spam URL shortener domains using a curated blocklist.
This package provides a reliable way to check if an arbitrary URL or domain string belongs to a known link shortener (
such as bit.ly, t.co, tinyurl.com). It helps developers protect their platforms from re-linking spam, malicious
redirects, chain shortening, and automated bot activities.
Key Benefits
- High Performance: The blocklist is parsed and loaded into an in-memory
setupon the first call, cached seamlessly viafunctools.lru_cache. Subsequent checks require zero disk I/O overhead providing immediate $O(1)$ lookups. - Smart Input Normalization: Transparently strips whitespace, ignores casing, drops
www.prefixes, and securely handles both absolute URLs (with protocols) and naked domain variants.
📦 Installation
Install the package via pip or using uv:
# Using standard pip
pip install antispam-link-shorteners
# Using uv (Recommended)
uv add antispam-link-shorteners
🚀 Usage
The library exposes two main public functions: is_link_shortener and link_shorteners_list.
1. Checking a URL (is_link_shortener)
The is_link_shortener() function takes an incoming string, normalizes it, runs security validation checks, and returns
a
boolean indicating whether the core domain is a known shortener.
from antispam_link_shorteners import is_link_shortener
# Handled successfully across various input layouts:
print(is_link_shortener("bit.ly")) # True
print(is_link_shortener(" BIT.LY ")) # True (casing & whitespace)
print(is_link_shortener("www.bit.ly")) # True (www stripping)
print(is_link_shortener("[https://www.bit.ly/abc?p=1](https://www.bit.ly/abc?p=1)")) # True (path/query parsing)
# Legitimate domains pass through:
print(is_link_shortener("https://github.com")) # False
Exception Handling & Security Guardrails
is_link_shortener() explicitly protects execution workflows by enforcing strict data structural criteria:
from antispam_link_shorteners import is_link_shortener
try:
is_link_shortener(12345) # TypeError
except TypeError:
...
try:
is_link_shortener(" ") # ValueError
except ValueError:
...
try:
is_link_shortener("www.ggaaa") # ValueError
except ValueError:
...
2. Fetching the Underlying Raw List (link_shorteners_list)
Use link_shorteners_list() to interact directly with the underlying cached set of clean, lowercase blacklisted
domains:
from antispam_link_shorteners import link_shorteners_list
banned_set = link_shorteners_list()
print(type(banned_set)) # <class 'set'>
print("tinyurl.com" in banned_set) # True (O(1) memory lookup)
👥 Credits & Attribution
This library relies on the following open-source resources:
- Data Source: The domain blocklist text file is directly sourced from the PeterDaveHello/url-shorteners.
- Original Project: This project represents a heavily refactored, type-hinted, performance-optimized, and modernized Python alternative inspired by mayakyler/link-shorteners.
⚖️ License
This project uses a multi-license structure to cleanly respect all upstream authors:
- Modified library: Licensed under the MIT License.
- Original library: Licensed under the MIT License.
- Blocklist Dataset: Distributed under the Creative Commons Attribution-ShareAlike 4.0 International License ( CC-BY-SA-4.0).
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 antispam_link_shorteners-0.2.0.tar.gz.
File metadata
- Download URL: antispam_link_shorteners-0.2.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfc3e630d2828ad6266a02da1966131b63e05002e3183c8def04c9354b3c97ea
|
|
| MD5 |
878b09c348b55be51aec2e2acd3495c6
|
|
| BLAKE2b-256 |
289d1093afdd0c23f8528b759a66a619ec7d3fbcdcf27150363dd880217d9972
|
File details
Details for the file antispam_link_shorteners-0.2.0-py3-none-any.whl.
File metadata
- Download URL: antispam_link_shorteners-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d166e09db75fcd5944a69bfb2465c395719a5d599d1fa0b1feac862fa44ea78
|
|
| MD5 |
6624b73a2e10b3b707e6d436bb0892aa
|
|
| BLAKE2b-256 |
71c468efe2794cd194f470395ce44f19d86e88be7cb8adbe76c97b394fa7fab2
|