Provides a NiceGUI `Element` wrapper for integrating hCaptcha (https://www.hcaptcha.com/) into a NiceGUI application.
Project description
NiceGUI hCaptcha Element
Reusable hCaptcha integration for NiceGUI applications.
Features:
- Async token retrieval
- Server-side verification
- Hook-based extensibility
Installation
pip install nicegui-hcaptcha
You also need:
- hCaptcha site key
- hCaptcha secret key
Both are available in the hCaptcha dashboard.
Quick Start
from nicegui import ui
from nicegui_hcaptcha import HCaptcha
captcha = HCaptcha(site_key="your_site_key_here")
async def submit():
result = await captcha.verify(secret="your_secret_key_here")
if not result.success:
ui.notify(f"Captcha failed: {result.error_codes}")
return
ui.notify("Captcha verified")
ui.button("Submit", on_click=submit)
That is sufficient for basic usage.
Verification Result
verify() returns:
HCaptchaResult(
success: bool,
error_codes: Sequence[HCaptchaErrorCode] | None,
token: str | None,
)
You are responsible for handling UI behavior.
Error Codes
Official hCaptcha Codes
missing-input-secretinvalid-input-secretmissing-input-responseinvalid-input-responseexpired-input-responsealready-seen-responsebad-requestmissing-remoteipinvalid-remoteipnot-using-dummy-passcodesitekey-secret-mismatch
Custom Integration Codes
-
captcha-not-completedReturned ifverify()is called before user completion. -
verification-request-failedReturned if the verification request fails or response parsing fails.
Registering Hooks
You can register async callbacks:
async def on_captcha(result: HCaptchaResult) -> None:
if result.success:
print("Verified")
else:
print("Failed:", result.error_codes)
captcha.on_verified(on_captcha)
Hooks are executed after each verification.
Resetting the Widget
await captcha.reset()
This forces the user to complete a new challenge.
Minimal Pattern for Forms
Typical pattern:
result = await captcha.verify(secret)
if not result.success:
return
# continue form processing
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 nicegui_hcaptcha-0.1.0.tar.gz.
File metadata
- Download URL: nicegui_hcaptcha-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cefeca9656f0d9f7b1eaa281470f69ead628bbba48915c90ee7388b2e936f802
|
|
| MD5 |
2dbe5252404922ce2153866de44ed442
|
|
| BLAKE2b-256 |
648a01152ac214d9c3722ffad527aac2a0f897f9147ebded5ba38d499c2b426d
|
File details
Details for the file nicegui_hcaptcha-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nicegui_hcaptcha-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07d021405467a20ff07ac40343e4af19afd79e09005e54188ab041cc65328bce
|
|
| MD5 |
6ce9bcfcdc5183a84dee9bc10ca32684
|
|
| BLAKE2b-256 |
e311d42f78f6e37866f37dd106ecfbbffdae0accb7a12cb2333c0de0e23b610e
|