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.1

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.1
File Size Uploaded Provenance
gbkomi_captcha-0.1.1.tar.gz 11.3 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 24.5 kB

Release files / gbkomi_captcha-0.1.1.tar.gz

Download URL gbkomi_captcha-0.1.1.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f9d18d9e05db51979516d37cb102345d5091dbba0158e9631a497b9838e95651
BLAKE2b-256 checksum
How to use checksums
724bc23ccb919b01c37424a60186304b1ed7ba6c779c31c5d7201aeb9d1e3864
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.1-py3-none-any.whl

Download URL gbkomi_captcha-0.1.1-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e8105f2f0a164fafc08bb0b873efc4b9a8c7088c04e22ca5ae742cbb34450a7
BLAKE2b-256 checksum
How to use checksums
d55f75864dea4b781dfe17e5414c18e1af5cb1b9afa7379625fbba19f031cac9
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.1

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.1 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