captcha: A Python Library for Audio and Image CAPTCHAs

This repository profile is provided by osrepos.com, an open source repository discovery platform.

captcha: A Python Library for Audio and Image CAPTCHAs

Summary

captcha is a Python library designed to generate both audio and image CAPTCHAs. It offers a straightforward way to integrate robust human verification into web applications, enhancing security and user experience. With customizable options for fonts, voices, and colors, it provides flexibility for various project needs.

Repository Information

Analyzed by OSRepos on November 5, 2025

Topics

Click on any tag to explore related repositories

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

The captcha library by lepture is a powerful Python tool for generating both audio and image CAPTCHAs. It provides a simple yet effective solution for implementing human verification challenges, crucial for preventing spam and automated abuse on websites and applications. This library is written in Python and is widely used for its ease of integration and flexibility.

Installation

Installing captcha is straightforward using pip. Open your terminal or command prompt and run the following command:

pip install captcha

This will install the library and its dependencies, allowing you to start generating CAPTCHAs immediately.

Examples

The library separates audio and image CAPTCHA generation into distinct modules, making it easy to use. Here are examples demonstrating how to generate both types of CAPTCHAs and how to customize image colors.

Basic Usage:

from captcha.audio import AudioCaptcha
from captcha.image import ImageCaptcha

audio = AudioCaptcha(voicedir='/path/to/voices') # Optional: use your own voice data
image = ImageCaptcha(fonts=['/path/A.ttf', '/path/B.ttf']) # Optional: use your own font data

# Generate audio CAPTCHA
data_audio = audio.generate('1234')
audio.write('1234', 'out.wav')

# Generate image CAPTCHA
data_image = image.generate('1234')
image.write('1234', 'out.png')

While the library includes built-in voice and font data, it is recommended to use your own custom data for production environments.

Custom Colors for Image CAPTCHA:

You can easily customize the background and foreground colors of your image CAPTCHAs by specifying RGB tuples.

from captcha.image import ImageCaptcha

image = ImageCaptcha(fonts=['/path/A.ttf', '/path/B.ttf'])

# Red text on a yellow background
image.write('1234', 'out.png', bg_color=(255, 255, 0), fg_color=(255, 0, 0))

Why Use

The captcha library stands out for its simplicity and effectiveness in generating both visual and auditory challenges. Its Pythonic interface makes it easy for developers to integrate robust CAPTCHA functionality into their projects. Whether you need to protect forms, prevent bot registrations, or secure sensitive actions, captcha offers a reliable and customizable solution. The ability to use custom fonts and voices also allows for greater brand consistency and accessibility.

Links

For more detailed information, documentation, and to contribute to the project, refer to the official links:

Source repository

Open the original repository on GitHub.

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️