Skip to main content

Animated visual captcha generation library using Manim.

Project description

Manim-Captcha

captcha_circle captcha_matrix captcha_piramid

Overview

Animated visual captcha generation library using Manim Framework.

Traditional CAPTCHAs are static images. Manim-Captcha generates animated visual challenges (e.g., moving selectors, distributed numbers, dynamic noise).

This library offers:

  • A "Captcha Generator" that allows to request generation of captcha files.
  • A "Captcha Automatic Generator" for async operation that acts as a background process to automatically generate captcha files in the filesystem for a custom interval and keeping a maximum number of captchas files (file rotation).
  • Some builtin captchas animations that you can select to use.
  • Kind of "plugin" based system were you can provide any external custom Manim captcha animation script (scene) and make the library use it.
  • Easy way to pass custom properties to the captcha scenes for customization (like scenes).

Table of Contents

Requirements

The manim-captcha library requires python 3 (tested with v3.12), Manim Community framework, and the corresponding requirements for Manim (like Cairo and Pango libraries).

Installation

Note: The next installation instructions are for Debian based Linux systems.

From a command line, install the different requirements:

sudo apt-get update
sudo apt-get install build-essential make python3 python3-dev python3-pip
sudo apt-get install libcairo2-dev libpango1.0-dev

The library has been published to pypi so can be easily installed via pip:

pip install manim-captcha

Usage

Basic captcha generator:

from manim_captcha.generator import CaptchaGenerator
from manim_captcha.scenes import CaptchaScene
from pathlib import Path

generator = CaptchaGenerator()

captcha = generator.generate(
    code="1234",
    scene=CaptchaScene.CIRCLE_NUMS,
    out_dir=Path("./captchas"),
    properties={
        "theme": "dark",
        "noise": True
    }
)

if captcha.error:
    print("Fail to create the captcha:")
    print(captcha.error_info)
else:
    print("Captcha successfully created")
    print(f"  Code: \"{captcha.code}\"")
    print(f"  File: {captcha.file}")
print("")

Async and non-blocking automatic captcha generator:

import asyncio
import logging
from manim_captcha.auto_generator import CaptchaAutoGenerator
from pathlib import Path

logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.INFO
)
logger = logging.getLogger(__name__)

async def main():
    # Setup the CaptchaAutoGenerator
    MAX_NUM_CAPTCHAS = 5
    TIME_GEN_INTERVAL_S = 10
    OUT_DIR = Path("./captchas")
    auto_generator = CaptchaAutoGenerator(
        OUT_DIR, TIME_GEN_INTERVAL_S, MAX_NUM_CAPTCHAS)
    # Start the generator process
    start_success = await auto_generator.start()
    if not start_success:
        logger.error("Fail to Start CaptchaAutoGenerator")
        return
    # Wait and get some captchas during 1 minute
    TIME_CHECK = 60
    time_pass_s = 0
    run = True
    while run:
        # Show number of captchas availables
        num_captchas = auto_generator.num_captchas()
        logger.info("Num Captchas Availables: %d", num_captchas)
        # Try to get a captcha
        captcha = auto_generator.get_captcha()
        if not captcha.error:
            logger.info("Captcha retrieved:")
            logger.info("  Code: \"%s\"", captcha.code)
            logger.info("  File: %s", str(captcha.file))
        await asyncio.sleep(TIME_GEN_INTERVAL_S)
        # Check if check end time has arrive to exit the loop
        time_pass_s = time_pass_s + TIME_GEN_INTERVAL_S
        if time_pass_s >= TIME_CHECK:
            run = False
    # Stop the generator process
    await auto_generator.stop()

if __name__ == '__main__':
    asyncio.run(main())

Note: You can find some extra usages in the examples/ directory.

Library Development

For library development, to ease project setup and installation of all the requirements, a Makefile and some bash scripts are provided for Linux systems based on Debian.

Setup the project (this will install all system requirements and creates a python virtual environment):

make setup

Extra actions can be performed through make, just run make without argments to see the usage help:

make

Usage:
  setup: Setup Project and install requirements
  test: Run project tests
  check_code_style: Run Code Style Checks
  check_static_types: Run Static Types Checks
  install: Install local package in edit mode
  publish: Publish the library to pypi

Now open any code editor (i.e. vscode) withing the python environment and start coding!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

manim_captcha-1.2.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

manim_captcha-1.2.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file manim_captcha-1.2.0.tar.gz.

File metadata

  • Download URL: manim_captcha-1.2.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for manim_captcha-1.2.0.tar.gz
Algorithm Hash digest
SHA256 640a937f89b74658064f84040738e4facadd8ab15476e538bde72a2c070281e5
MD5 4d8e3765309e0fd1fdaf09c2abd5078a
BLAKE2b-256 1d11f559c8ca59bf09320b6d8b761ca49508c10d4cf716d4d2a2d7e985f2763b

See more details on using hashes here.

File details

Details for the file manim_captcha-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: manim_captcha-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for manim_captcha-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7caa57d79c5aa5c8a272a59d055ee5e770c5e9d2cc403f785ecba0069de055a0
MD5 25b28f84e2840fc53f3f3c6f7cf0e731
BLAKE2b-256 807a01c9eb2b9901d5dee5e3898cb7d18e08bd1ee5fef5709af114eebcade811

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page