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
Metadata
Release files for nicegui-hcaptcha 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nicegui_hcaptcha-0.1.0.tar.gz | 4.1 kB | Without provenance | Details for nicegui_hcaptcha-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nicegui_hcaptcha-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for nicegui_hcaptcha-0.1.0-py3-none-any.whl |
Total release size: 9.8 kB
Release files / nicegui_hcaptcha-0.1.0.tar.gz
| Download URL | nicegui_hcaptcha-0.1.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cefeca9656f0d9f7b1eaa281470f69ead628bbba48915c90ee7388b2e936f802
|
|
BLAKE2b-256 checksum How to use checksums |
648a01152ac214d9c3722ffad527aac2a0f897f9147ebded5ba38d499c2b426d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.12
|
Release files / nicegui_hcaptcha-0.1.0-py3-none-any.whl
| Download URL | nicegui_hcaptcha-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07d021405467a20ff07ac40343e4af19afd79e09005e54188ab041cc65328bce
|
|
BLAKE2b-256 checksum How to use checksums |
e311d42f78f6e37866f37dd106ecfbbffdae0accb7a12cb2333c0de0e23b610e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.12
|
Security for nicegui-hcaptcha 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.