Skip to main content

DisCapTy

DisCapTy's LogoDisCapTy's Logo

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:
    # This generator returns an obfuscated text.
    captcha_for_user = discapty.TextGenerator().generate(initial_input)
    # Create a Captcha object, the first argument is the clear code, the second is the obfuscated code. Anything goes.
    return discapty.Captcha(initial_input, captcha_for_user)

# Generate your Captcha.
captcha = generate_a_captcha("12345")

# Show the obfuscated code. See https://discapty.readthedocs.io for more information on this object.
show_captcha_to_user(captcha.captcha)

Checking user's input

import discapty

# Generate your Captcha.
captcha: discapty.Captcha = generate_a_captcha("12345")

# This is your user's input here
user_input: str = '12345'

if captcha.check(user_input) is True:
    # The user input is correct
    print("Correct!")
else:
    # The user input is incorrect
    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()

# We cannot provide typehint here, `captcha` is a `typing.Any` and cannot help you, it'll be your
# job to know what you'll get as a captcha.
send_captcha_to_user(captcha)
user_input: str = get_user_input()

is_correct: bool = challenge.check(user_input)
# If the user's input is correct, the challenge ends, if not, `challenge.attempted_tries` will get
# +1, and if it is greater than the retries that has been set, then an error is raised when using
# `.check`

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: PyPI - License

DisCapTy uses the Roboto font as default font. This font is licensed under Apache-2.0.

Metadata

Release files for discapty 2.2.0

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

Source distribution (sdist)

Source distribution for discapty 2.2.0
File Size Uploaded
discapty-2.2.0.tar.gz 106.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discapty 2.2.0
File Interpreter ABI Platform
discapty-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 215.3 kB

Release files / discapty-2.2.0.tar.gz

Download URL discapty-2.2.0.tar.gz
Size 106.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c9fbffbd3c03679783c54cee2d228bb1eeb0689ab29c7bff4e5662f2123398e5
BLAKE2b-256 checksum
How to use checksums
a08fee8f594a5d2c86a310598bc5f6ac0d26d2fd95c7706def465cbb3b5fe198
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.9.13 Windows/10

Release files / discapty-2.2.0-py3-none-any.whl

Download URL discapty-2.2.0-py3-none-any.whl
Size 108.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01cbed4ec3fe6f738c27b9e3fa4adc2bbf610429e278aef90f8b7b94871afc54
BLAKE2b-256 checksum
How to use checksums
d02c5ad965f9e192d9f4a2084af16ffa67e410c02592cb3e674d5e8e41d56e7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.9.13 Windows/10

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.4

2 release files

0.3.2

2 release files

0.3

2 release files

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