Bengali CAPTCHA
The first Bengali text-based CAPTCHA library, designed for easy integration into applications.
bengali-captcha is a Pillow-based library for generating image CAPTCHAs using Bengali letters and digits—the first of its kind for the Bengali language. Developed from the research implementation presented in A Usable and Secure Bengali CAPTCHA[NMI Shibbir et al, Computers and Security 2024], it offers six rendering variants through a simple Python API, with output as Pillow images, in-memory streams, or image files. The accompanying study demonstrated the CAPTCHA designs’ usability and resistance to the automated attacks evaluated.
The PyPI package includes the original Bengali fonts and background images.
Installing it with pip installs those assets too. All six CAPTCHA variants
select their bundled assets automatically: no font path, background path,
separate download, or configuration is required.
The project is associated with the research paper A Usable and Secure Bengali CAPTCHA. If you use this library in your research, please cite the paper using the BibTeX entry in the Citation section below.
Sample CAPTCHA
Features
- Six rendering variants with automatically selected fonts and backgrounds.
- Bundled assets for offline generation after installation.
- Random Bengali challenge text generated using Python's
secretsmodule. - Custom challenge text, text-source callables, and configurable random-text length.
- Adjustable image size, margins, noise, and output format.
- Optional custom fonts, backgrounds, and supported text colors.
- Pillow image, in-memory stream, and file output.
- Command-line interface and a Django integration example.
Installation
Requires Python 3.10 or newer.
python -m pip install bengali-captcha
Quick start
The original Bengali fonts and background images are included. Generate a CAPTCHA immediately, with no font downloads or custom image paths:
from bengali_captcha import BengaliCaptcha
captcha = BengaliCaptcha()
answer, image = captcha.image
image.save("captcha.png")
All six variants work out of the box:
for variant in range(1, 7):
answer, path = BengaliCaptcha(variant=variant).write(f"captcha-{variant}.png")
Default challenge lengths match the original site: 3-4 characters for variants
1, 3 and 5, and 3-5 for variants 2, 4 and 6. Challenge text uses the original
Bengali alphabet and digit selection with secrets randomness.
Pass length=5 to change the length, or supply a string or callable as source.
To generate a longer random challenge:
captcha = BengaliCaptcha(length=5)
answer, image = captcha.image
image.save("captcha.png")
Output options
| API | Returns |
|---|---|
captcha.image |
(answer, image), where image is a Pillow image |
captcha.bytes |
(answer, stream), where stream is a BytesIO object positioned at the beginning |
captcha.write("captcha.png") |
(answer, path), after writing a newly generated image to disk |
Generate image bytes using the included assets:
captcha = BengaliCaptcha(variant=2, source="কখ১২")
answer, stream = captcha.bytes # BytesIO, positioned at the beginning
png_data = stream.getvalue()
To generate and save directly to a file:
answer, path = captcha.write("captcha.png")
Each access to .image, .bytes, or .write() creates a new image and calls
the text source again. Keep the answer returned by the same call as the image
you display. To save that exact image, use its .save() method as shown in the
quick start.
Command-line usage
bengali-captcha captcha.png
bengali-captcha captcha.png --variant 1 --length 4
python -m bengali_captcha captcha.png --variant 6
These commands use the included fonts and images. The only filename required is where to save the generated PNG. The command prints its answer in UTF-8.
Django integration
Generate bytes for each request and keep the corresponding answer in the user's session. For example, inside a Django view:
from django.http import HttpResponse
from bengali_captcha import BengaliCaptcha
def captcha_image(request):
answer, stream = BengaliCaptcha().bytes
request.session["captcha_answer"] = answer
response = HttpResponse(stream.getvalue(), content_type="image/png")
response["Cache-Control"] = "no-store"
return response
Your form-processing view must validate the submitted answer against the stored value and enforce challenge expiration, one-time use, and rate limiting. Keep the answer on the server; the image response should contain only the image.
Optional: use your own font or background
Skip this section to use the original CAPTCHA styles. Supply font or
background only when you want to replace a bundled asset; each override is
independent, so the asset you do not override keeps its bundled default.
from bengali_captcha import BengaliCaptcha
# Optional custom font; the background still comes from the package.
captcha = BengaliCaptcha(variant=2, font="my-bengali-font.ttf")
# Optional custom background; the font still comes from the package.
captcha = BengaliCaptcha(variant=2, background="my-background.png")
# Optional: replace both assets.
captcha = BengaliCaptcha(
variant=2,
font="my-bengali-font.ttf",
background="my-background.png",
)
answer, image = captcha.image
Custom fonts must support Bengali characters. A custom font path or Pillow
font object works with every variant. Custom backgrounds apply to variants
1, 2, 3, 4 and 5. Omitting either argument or passing None uses its bundled
default; background=False selects a white canvas.
The command line also accepts optional overrides:
bengali-captcha captcha.png --variant 2 --font my-bengali-font.ttf --background my-background.png
Citation
If you use Bengali CAPTCHA in your research, experiments, or academic publications, please cite the following paper:
Md Neyamul Islam Shibbir, Md Hasibur Rahman, Farida Chowdhury, and Md Sadek Ferdous. A Usable and Secure Bengali CAPTCHA. arXiv preprint arXiv:2606.29077, 2026.
@article{shibbir2026usable,
title={A Usable and Secure Bengali CAPTCHA},
author={Shibbir, Md Neyamul Islam and Rahman, Md Hasibur and Chowdhury, Farida and Ferdous, Md Sadek},
journal={arXiv preprint arXiv:2606.29077},
year={2026}
}
Development and publishing
From the repository root, install the package in editable mode:
python -m pip install -e .
Install the release tools, run the tests, build the distributions, and check the package metadata:
python -m pip install -e ".[release]"
python -m unittest discover -s tests -v
python -m build
python -m twine check --strict dist/*
Acknowledgements
The generators are loosely derived from
Claptcha by Piotr Kuszaj.
Bengali-specific variant changes originate in the captchaWeb research application.
License and credits
MIT License
Copyright (c) 2026 Md Neyamul Islam Shibbir, Md Hasibur Rahman, Md Sadek Ferdous, Farida Chowdhury
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Metadata
Release files for bengali-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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bengali_captcha-0.1.2.tar.gz | 628.5 kB | Without provenance | Details for bengali_captcha-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bengali_captcha-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for bengali_captcha-0.1.2-py3-none-any.whl |
Total release size: 1.3 MB
Release files / bengali_captcha-0.1.2.tar.gz
| Download URL | bengali_captcha-0.1.2.tar.gz |
|---|---|
| Size | 628.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fee23668be92479b600cf4d717ab2e9942ce19d6470266e3b64d639dea232db
|
|
BLAKE2b-256 checksum How to use checksums |
c9bc906378c69316124b3a2b87f7fe0e9812b0321a20c57fa947190102826854
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Release files / bengali_captcha-0.1.2-py3-none-any.whl
| Download URL | bengali_captcha-0.1.2-py3-none-any.whl |
|---|---|
| Size | 645.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5785c4067307bb2a395b21491d4d05842cfb7cbe91b895afa79aea85057b9ca6
|
|
BLAKE2b-256 checksum How to use checksums |
1fadbca30a38d08972cad0d3b514be6eb65a3f6f4759be3f389d9208d1bcceb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.3
|
Security for bengali-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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.