Skip to content

Creating a Generator

Sepehr0Day edited this page Jun 13, 2026 · 1 revision

Creating a Generator

Use VisualChallenge when the generator creates a visual asset.

from PIL import Image, ImageDraw

from CaptchaGenerator.core import ChallengeResult, VisualChallenge


class ExampleCaptcha(VisualChallenge):
    def generate(
        self,
        *,
        name_export: str,
        path_export: str,
    ) -> ChallengeResult:
        config = self._config(None)
        image = Image.new("RGB", config.size, config.background_color)
        draw = ImageDraw.Draw(image)
        draw.text((40, 40), "Question", fill=config.foreground_color)

        return self._save(
            image,
            path_export=path_export,
            name_export=name_export,
            answer="answer",
            prompt="Enter the answer.",
            metadata={},
            config=config,
        )

Then:

  1. Add the module to CaptchaGenerator/generators.
  2. Export the class from generators/__init__.py and package __init__.py.
  3. Add it to SUPPORTED_CAPTCHAS.
  4. Add focused tests.
  5. Add simple.py and interactive.py examples.
  6. Document answer and metadata contracts.

Clone this wiki locally