DisCapTy
DisCapTy is a highly type hinted Python module to generate Captcha images without struggling your mind on how to make your own. Everyone can use it!
Documentation: https://discapty.readthedocs.io/
Installing
DisCapTy is available on PyPi!
pip3 install discapty
To use DisCapTy, you need a Python version equal or greater to 3.7
and below 3.11
.
Clone & Test the project
This project is dependant of Poetry, a dependency management tool. You are most likely going to require this tool to correctly interact with the project & its dependencies, check out Poetry's documentation for how to install it.
To clone the repository: git clone https://github.com/Predeactor/DisCapTy.git
To install dependencies: poetry install
To run tests: poetry run python -m unittest
Creating Captcha
For DisCapTy, a Captcha is simply a code with any possible objects that can be returned, for example, it is one code (Like "12345") with an image (Usually a PIL.Image.Image
object)
This is because DisCapTy uses the concept of generators that are used to generate a captcha from a given code, and it can return anything.
DisCapTy comes with 3 builtin generators:
- TextGenerator : Text based captcha
- WheezyGenerator : Image based captcha
- ImageGenerator : Image based captcha
Creating Captcha manually
import discapty
def generate_a_captcha(initial_input: str) -> discapty.Captcha:
captcha_for_user = discapty.TextGenerator().generate(initial_input)
return discapty.Captcha(initial_input, captcha_for_user)
captcha = generate_a_captcha("12345")
show_captcha_to_user(captcha.captcha)
Checking user's input
import discapty
captcha: discapty.Captcha = generate_a_captcha("12345")
user_input: str = '12345'
if captcha.check(user_input) is True:
print("Correct!")
else:
print("Incorrect!")
What's great with the .check
method is that you can specify if you need to remove space in the user's input and/or check casing.
Creating Captcha manually is not a recommended way, because DisCapTy comes with its opinionated challenge runner & is inefficient anyway.
Create a Challenge
import discapty
challenge = discapty.Challenge(discapty.TextGenerator(), retries=3)
captcha = challenge.begin()
send_captcha_to_user(captcha)
user_input: str = get_user_input()
is_correct: bool = challenge.check(user_input)
Please see the documentation for more information on how the library work.
Contact
You can join my Discord server for any help: https://discord.gg/WdcFUH7ths
DisCapTy is an open-source project distributed under the MIT license:
DisCapTy uses the Roboto font as default font.
This font is licensed under Apache-2.0.