Skip to main content
# gbkomi-captcha

🔐 Advanced CAPTCHA generator with visual distortion, noise, and wave deformation.  
Designed to be **bot-proof** for web applications and Telegram bots.

## Features

- ✅ **Image-based CAPTCHA** (numbers or short text)
- ✅ **Wave distortion** + random rotation per character
- ✅ **Noise lines & dots** to defeat OCR
- ✅ **Rate limiting** and **challenge expiration**
- ✅ **One-time use** verification
- ✅ Ready-to-use **Flask**, **FastAPI**, and **Telegram** integrations
- ✅ Pluggable storage backend (Memory / Redis)

## Installation

```bash
pip install gbkomi-captcha

For Redis support:

pip install gbkomi-captcha[redis]

For web integrations:

pip install gbkomi-captcha[web]

For Telegram bots:

pip install gbkomi-captcha[telegram]

Quick Start

Generate a CAPTCHA image

from gbkomi_captcha import CaptchaGenerator
from gbkomi_captcha.middleware.challenge import create_challenge

gen = CaptchaGenerator()
image, text = gen.generate()  # e.g. "8342"

challenge_id = create_challenge(text, ttl=120)

# Send `image` to the user, keep `challenge_id`
# Later verify with:
# from gbkomi_captcha.middleware.validators import validate_answer
# is_valid = validate_answer(challenge_id, user_input)

With Flask

from flask import Flask
from gbkomi_captcha.integrations.flask import flask_blueprint

app = Flask(__name__)
app.register_blueprint(flask_blueprint, url_prefix="/api")

# GET /api/captcha/image → returns PNG with X-Captcha-Id header
# POST /api/captcha/verify → JSON { "challenge_id": "...", "answer": "1234" }

With FastAPI

from fastapi import FastAPI
from gbkomi_captcha.integrations.fastapi import fastapi_router

app = FastAPI()
app.include_router(fastapi_router, prefix="/api")

With Telegram Bot

from telegram.ext import Application
from gbkomi_captcha.integrations.telegram import TelegramCaptcha

app = Application.builder().token("TOKEN").build()
captcha = TelegramCaptcha(app.bot)

# Inside a handler:
# await captcha.send_captcha(chat_id, user_id)
# Then later:
# await captcha.verify(chat_id, user_id, challenge_id, answer)

Configuration

You can override default settings:

config = {
    "length": 6,
    "charset": "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
    "width": 200,
    "height": 80,
    "noise_level": 0.4,
    "distortion_strength": 4.0,
    "ttl_seconds": 60,
    "max_attempts": 3,
    "rate_limit": 5,
}
gen = CaptchaGenerator(config)

Storage Backends

  • MemoryStorage: in-memory dict (default, for testing)
  • RedisStorage: persistent with TTL (production)
from gbkomi_captcha.storage.redis import RedisStorage
from gbkomi_captcha.middleware.challenge import get_storage

storage = RedisStorage(host="localhost", port=6379, db=0)
# Replace the default storage globally
import gbkomi_captcha.middleware.challenge as challenge
challenge._storage = storage

Security Notes

  • The CAPTCHA answer is never sent to the client.
  • Each challenge is one-time use and expires after TTL.
  • Rate limiting prevents brute-force attacks.
  • Wave distortion + random noise make OCR extremely difficult.

Requirements

  • Python >= 3.10
  • Pillow (image processing)

License

MIT

Author

GBKOMI

Metadata

Release files for gbkomi-captcha 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gbkomi-captcha 0.1.2
File Size Uploaded Provenance
gbkomi_captcha-0.1.2.tar.gz 11.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gbkomi-captcha 0.1.2
File Interpreter ABI Platform
gbkomi_captcha-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / gbkomi_captcha-0.1.2.tar.gz

Download URL gbkomi_captcha-0.1.2.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
db4123b81b89ecb4eb229106efced739b5cef077c12b993201ef6b1a2d5682c1
BLAKE2b-256 checksum
How to use checksums
8567888ddc9f20bffb07cca2b9034f0518b06f6503a226c72c5c1b4a44dddbbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / gbkomi_captcha-0.1.2-py3-none-any.whl

Download URL gbkomi_captcha-0.1.2-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db06a6425f7d3de01446766d3cd6a60b58b6802105ae059b4dec4cf2f5baafe5
BLAKE2b-256 checksum
How to use checksums
8f3685b7ceec7eb48c33c0a8c60ea543fd4ddfc94722965089e4e2bba151c093
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for gbkomi-captcha 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page