A simple captcha generator
Project description
captcha-cli
A simple captcha generator
I. Introduction
This is a simple captcha generator that utilizing pillow and pydub to generate captcha.
This also include a simple CLI to help you manage captcha level and data.
II. Installation
1. Base installation
You can install this package using pip:
pip install captcha-cli
or with uv:
uv add captcha-cli
2. manage installation
You can install this package with DB driver using pip:
pip install 'captcha-cli[manage]'
or with uv:
uv add 'captcha-cli[manage]'
This package comes with DB library (sqlalchemy) and default driver (aiosqlite)
3. api installation
You can install this package with API support using pip:
pip install 'captcha-cli[api]'
or with uv:
uv add 'captcha-cli[api]'
This package comes with DB part (sqlalchemy and aiosqlite) and API part (fastapi)
4. Using Docker
You can pull latest Docker image to your machine and use it:
docker pull git.vaito.dev/vair.nooi/captcha:latest
Or using dev image:
docker pull git.vaito.dev/vair.nooi/captcha:dev-latest
Or any dev build image:
docker pull git.vaito.dev/vair.nooi/captcha:<image id>
III. Usage
1. CLI
a. Add captcha level
-
Text captcha:
captcha add text --level <int> --angle <int> <int> --lines <int> <int> --dots <int> <int> --amplitude <int> --wavelength <int>-L / --level <int>act as the level id-a / --angle <int> <int>the range of the rotation angle of each character-l / --lines <int> <int>the range of the number of lines will be on the image-d / --dots <int> <int>the range of the number of dots will be on the image-A / --amplitude <int>the amplitude of distortion-w / --wavelength <int>the wavelength of distortion- Note
amplitudeandwavelengthwill decide how the picture will be bent
-
Audio captcha:
captcha add audio --level <int> --white-noise <int> <int> --pitch-shift <int> <int>-L / --level <int>act as the level id-w / --white-noise <int> <int>the range of the volume of the background noise, both int are negative number-p / --pitch-shift <int> <int>the range of the shift of each character pitch- Notes:
- For white noise volumne, -35 is very quiet, 0 is super dupper loud
- The pitch shift should be from 1 to 12
- The pitch is kinda useless
b. Delete captcha level
captcha delete --type [audio | text] --level <string>
-t / --type [audio | test]the type of the captcha-l / --level <string>the level id
c. List captcha levels
captcha list --type [audio | text]
-t / --type [audio | test]the type of the captcha
d. Generate captcha
captcha generate --type [audio | text] --level <string> --text <string> --length <int> --preview
-t / --type [audio | test]the type of the captcha-L / --level <string>the level id--text <string>the text to generate-k / --length <int>the length of random text-p / --previewpreview the captcha- Notes
- To use given text to generate captcha, use
--textoption - To use random text to generate captcha, use
--lengthoption --previewoption use pillowImage.show()for text captcha and pydubplay()for audio captcha--previewis required if you don't install package with DB option
- To use given text to generate captcha, use
e. Get all generated captcha (require DB installation)
captcha all --type [audio | text | both]
-t / --type [audio | text | both]captcha type filter
f. Start API server
captcha api --host <string> --port <int>
-h / --hostthe host adress-p / --portthe server port
2. API
Beside using CLI, you can also interact with app using API.
a. Start API
You can use this method
Or using Docker image:
docker run --name captcha -p 8000:8000 -v <path on your host>:/app/file git.vaito.dev/vair.nooi/captcha
b. Endpoints
-
POST
/captchaCreate a new captcha
-
Query:
type: "text" / "audio"captcha typenoise_level: stringcaptcha leveltext: string | null(default:null) predefined captcha answer, if null, use random textinclude_data: boolean(default:false) include base64 encoded captcha in the response
-
Return:
id: stringcaptcha id, use for getting answertype: "text" / "audio"captcha type, should match with the requested onedata: string | nullbase64 encoded captcha
-
-
POST
/solveSolve the captcha
-
Query:
id: stringcaptcha idanswer: stringcaptcha answer
-
Return:
status: "accepted" / "wrong"if the answer was true
-
-
GET
/captchaGet the captcha detail
-
Query:
id: stringcaptcha idwith_answer: boolean(defaultfalse) captcha answer, return error if env variableALLOW_GET_ANSWERis unset or set to false
-
Return:
id: stringcaptcha id, use for getting answertype: "text" / "audio"captcha typeanswer: stringcaptcha answer
-
Note: Field
answerin reponse would be omitted if querywith_answeris false
-
-
GET
/captcha/fileGet the captcha data
-
Query:
id: stringcaptcha id
-
Return:
- A JPG file if the captcha type is text
- or A WAV file if the captcha type is audio
-
IV. Env variables
| Name | Default value | Data type | Note |
|---|---|---|---|
| APP_LEVEL | Base on your installation | simple/manage/api | simple if you install captcha-climanage if you install captcha-cli[manage]api if you install captcha-cli[api] |
| DB_URL | sqlite+aiosqlite:///file/db.sqlite | string | Have to have the async dialect (driver) of the database (e.g. aiosqlite for sqlite)Should be accepted by sqlalchemy |
| ALLOW_GET_ANSWER | false | boolean | Set this to true to be able to get the captcha answer in API response |
| HOST | 127.0.0.1 | Any IP | |
| PORT | 8000 | integer |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file captcha_cli-1.0.1.tar.gz.
File metadata
- Download URL: captcha_cli-1.0.1.tar.gz
- Upload date:
- Size: 3.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ff7de15da84c491d4ccca141009357c14e8265bbaacdbc686aa6e1aa4b0b11d
|
|
| MD5 |
72f33d733b0080b4776cbc248acf04e0
|
|
| BLAKE2b-256 |
40f774b945c679dab0460205526fe8b4eb155bdb3a8f0a9eef13d6fc14ed9b84
|
File details
Details for the file captcha_cli-1.0.1-py3-none-any.whl.
File metadata
- Download URL: captcha_cli-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51f1975334a5aa5188e6de8069ddbc6f352c4956cbaad3b6bb84c06ea932e53f
|
|
| MD5 |
92126f6693704077175e1cc8c3a49acc
|
|
| BLAKE2b-256 |
632550f692ef49b7f2c9bf1f267739ace3b47197206202817e0007a944d392df
|