A professional, pluggable CAPTCHA library with image, math, and custom challenge types, token-based security, and multiple storage backends.
Project description
InnoCaptcha
A pluggable Python CAPTCHA library supporting image-based text challenges, arithmetic challenges, token-based security, and multiple storage backends.
PyPI · GitHub · Issues · Discussions
Table of Contents
Installation
pip install InnoCaptcha
Quick Start
1. Text CAPTCHA
Generates an image-based CAPTCHA with configurable text, colors, and dimensions. All images include random distortions and anti-aliasing.
from InnoCaptcha.text import TextCaptcha
# Basic usage
captcha = TextCaptcha()
captcha.create("abs")
print(captcha.verify("abs")) # True
captcha.save(r"captcha.png")
# Custom dimensions and colors
captcha = TextCaptcha(
width=350,
height=100,
color=(255, 137, 6),
background=(15, 14, 23)
)
captcha.create("abc123")
print(captcha.verify("wrong")) # False
captcha.save(r"captcha.jpg")
Constructor Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
width |
int or None |
300 |
Image width in pixels. |
height |
int or None |
80 |
Image height in pixels. |
color |
tuple[int, int, int] |
(0, 0, 0) |
Foreground (text) color in RGB. |
background |
tuple[int, int, int] |
(255, 255, 255) |
Background color in RGB. |
create(chars: str) — The text string to render in the CAPTCHA image. Required.
save() Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
str |
'captcha.png' |
Full file path or file name to write the image. |
Notes:
- Uses
secretsfor cryptographically strong randomness.- Rendering can be tuned via module-level constants such as
CHARACTER_OFFSET_DXandWORD_SPACE_PROBABILITY.
2. Math CAPTCHA
Generates arithmetic challenges (addition, subtraction, multiplication, division). All results are integers — the problem regenerates automatically if division would produce a fraction.
from InnoCaptcha.math import MathCaptcha
challenge = MathCaptcha()
print(challenge.get_question()) # e.g., "7 + 3 = ?"
print(challenge.answer) # e.g., 10
print(challenge.verify(10)) # True
print(challenge.verify("10")) # True — string input accepted
3. Command-Line Interface
# Display the installed version
InnoCaptcha --version
# Upgrade to the latest release on PyPI
InnoCaptcha --upgrade
API Reference
TextCaptcha
| Method / Attribute | Description |
|---|---|
create(chars: str) |
Renders the given string into a distorted CAPTCHA image. |
verify(input: str) |
Returns True if input matches the generated text. |
save(path) |
Writes the image to the specified file path. |
MathCaptcha
| Method / Attribute | Description |
|---|---|
get_question() -> str |
Returns the challenge string, e.g. "7 + 3 = ?". |
answer: int |
The correct integer answer to the current challenge. |
verify(input) -> bool |
Returns True if input equals the answer. |
Requirements
- Python 3.9 or later
- Pillow >= 10.0.0
License
MIT — InnoSoft Company
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 innocaptcha-1.2.0.tar.gz.
File metadata
- Download URL: innocaptcha-1.2.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2efff1f10efb4b80537a405bd2089b9584d72abbe79e7248a0661dda0d8b8296
|
|
| MD5 |
daac03de355677dc5c5aff21d6ae7aee
|
|
| BLAKE2b-256 |
fe4f432b8250fd6823b0d62cd9d02ad59a6838d8f7dac05ea6403355c54884fc
|
File details
Details for the file innocaptcha-1.2.0-py3-none-any.whl.
File metadata
- Download URL: innocaptcha-1.2.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d711e92c86962602fc171b2803f3cfae529c8f89c10fdb24ea9dc6053e99dc5
|
|
| MD5 |
1ecf1bd2e1fe97d81861246d44897250
|
|
| BLAKE2b-256 |
47c74282a39a9ebde610e23cf28f09afc3fc1843ac537264b1455bca0ed142e9
|