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")) # 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).
Metadata
Release files for antispam-link-shorteners 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| antispam_link_shorteners-0.2.2.tar.gz | 13.0 kB | Without provenance | Details for antispam_link_shorteners-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| antispam_link_shorteners-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for antispam_link_shorteners-0.2.2-py3-none-any.whl |
Total release size: 25.7 kB
Release files / antispam_link_shorteners-0.2.2.tar.gz
| Download URL | antispam_link_shorteners-0.2.2.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
82e08cdfc7ebe4d799236d23c39738b59a454347c3b8f80fbab348d6e0cadade
|
|
BLAKE2b-256 checksum How to use checksums |
e7213f60667814ef8e93cbc0401806924aecd1330bb94d5078bebec1c989c9d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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}
|
Release files / antispam_link_shorteners-0.2.2-py3-none-any.whl
| Download URL | antispam_link_shorteners-0.2.2-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
077ad9332e4897e533d8cf9b816cfd4146cdc55a01ce80848028d3ff4cc496cb
|
|
BLAKE2b-256 checksum How to use checksums |
d42347edf6a65fe9c92da6b6e30c54af7d88584f4de4091cffd13122ca3a3275
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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}
|
Security for antispam-link-shorteners 0.2.2
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.