# captcha: A Python Library for Audio and Image CAPTCHAs

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

Source: osrepos.com
Repository profile: https://osrepos.com/repo/lepture-captcha
Generated for open source discovery and AI-assisted research.

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.

GitHub: https://github.com/lepture/captcha
OSRepos URL: https://osrepos.com/repo/lepture-captcha

## 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.

## Topics

- captcha
- python
- security
- web development
- bot prevention
- audio captcha
- image captcha
- library

## Repository Information

Last analyzed by OSRepos: Wed Nov 05 2025 20:00:31 GMT+0000 (Western European Standard Time)
Detail views: 3
GitHub clicks: 2

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## 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:

bash
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:

python
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.

python
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:

*   [GitHub Repository](https://github.com/lepture/captcha)
*   [Official Documentation](https://captcha.lepture.com/)