============
Invisible spam protection for your Python apps — no CAPTCHA/reCaptcha, no puzzles, no math.
Spam attacks log - allows to view all filtered requests in the "Log of spam attacks". The log contains a detailed information about each request for a time period. At any time, you can check the request and make sure that the filtering is correct. A Python API for antispam service cleantalk.org. Invisible protection from spam, no captches, no puzzles, no animals and no math.
Tired of distorted images, puzzles with traffic lights, or invisible zebras? Here’s how CleanTalk compares:
| Feature | CAPTCHA | CleanTalk |
|---|---|---|
| User Experience | Interrupts with puzzles, images | Completely invisible |
| Setup Complexity | Medium to High | Easy integration with Python API |
| Mobile Usability | Often frustrating | Seamless experience |
| Accessibility (e.g. screenreaders) | Limited | Fully accessible |
| Spam Protection Method | Challenge-based (user solves) | Behavior-based (bot detection, JS, IP) |
| Requires User Interaction | ✅ Yes | ❌ No |
| Supports Form Relevance Checks | ❌ No | ✅ Yes |
CleanTalk uses multiple layers of protection:
- Spam bot signatures
- Blacklist checks (email, IP, domain)
- JavaScript presence
- Submission time analysis
- Comment relevance scoring
If you find this project useful, please consider starring ⭐ it on GitHub — it helps us grow and support development!
- Python 2.6+
- Python 3.x
- CURL support
- CleanTalk account — Sign up here
fromcleantalkimportCleanTalkimportjsonct=CleanTalk(auth_key='yourkey')
# ct.set_event_token_enabled(True) # See Bot-Detector Integration section belowct_result=ct.request(
message='abc', # Required. Visitor commentsender_ip='196.19.250.114', # Required. Visitor IP addresssender_email='stop_email@example.com', # Required. Visitor emailsender_nickname='spam_bot', # Required. Visitor nicknamepost_info=json.dumps({'post_url': 'https://yoursite.com'}), # Optional. Additional post info in JSON format.event_token='xxx'# Optional. Fill it with ct_bot_detector_event_token hidden input from your form (auto generate). See Bot-Detector Integration section below
)
#Checkifct_result['allow']:
print('Comment allowed. Reason '+ct_result['comment'])
else:
print('Comment blocked. Reason '+ct_result['comment'])API returns Python dictionary object, where keys:
- allow (0|1) - allow to publish or not, in other words spam or ham
- comment (string) - server comment for requests.
- id (string MD5 HEX hash) - unique request idenifier.
Run the next command in the terminal:
pipinstallcleantalk-python-antispamThen you can use Cleantalk class import:
fromcleantalk_python_antispam.cleantalkimportCleanTalkFor improved protection, integrate CleanTalk's bot-detector JavaScript on your website:
Add this JavaScript to your layout before </body> tag:
<scripttype="text/javascript" src="https://fd.cleantalk.org/ct-bot-detector-wrapper.js"></script>When you have integrated the bot-detector JavaScript, inform the API by setting the event_token_enabled flag:
ct=CleanTalk(auth_key='yourkey')
ct.set_event_token_enabled(True) # Tell API that bot-detector is enabledct_result=ct.request(
message='user comment',
sender_ip='196.19.250.114',
sender_email='user@example.com',
sender_nickname='username',
event_token='xxx'# Token from bot-detector JavaScript
)If you decide not to use bot-detector:
ct=CleanTalk(auth_key='yourkey')
ct.set_event_token_enabled(False) # Bot-detector is not enabledct_result=ct.request(
message='user comment',
sender_ip='196.19.250.114',
sender_email='user@example.com',
sender_nickname='username'
)True- bot-detector is integrated and enabled (JavaScript token will be used for advanced bot detection)False- bot-detector is not integrated or disabledNone(default) - no explicit bot-detector status specified
Version 1.3
- New. Now page URL could be added to the request.
- Mod. Tests file updated.
- Mod. Readme updated.
