Skip to main content

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-secret
  • invalid-input-secret
  • missing-input-response
  • invalid-input-response
  • expired-input-response
  • already-seen-response
  • bad-request
  • missing-remoteip
  • invalid-remoteip
  • not-using-dummy-passcode
  • sitekey-secret-mismatch

Custom Integration Codes

  • captcha-not-completed Returned if verify() is called before user completion.

  • verification-request-failed Returned 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nicegui_hcaptcha-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nicegui_hcaptcha-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for nicegui_hcaptcha-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cefeca9656f0d9f7b1eaa281470f69ead628bbba48915c90ee7388b2e936f802
MD5 2dbe5252404922ce2153866de44ed442
BLAKE2b-256 648a01152ac214d9c3722ffad527aac2a0f897f9147ebded5ba38d499c2b426d

See more details on using hashes here.

File details

Details for the file nicegui_hcaptcha-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nicegui_hcaptcha-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07d021405467a20ff07ac40343e4af19afd79e09005e54188ab041cc65328bce
MD5 6ce9bcfcdc5183a84dee9bc10ca32684
BLAKE2b-256 e311d42f78f6e37866f37dd106ecfbbffdae0accb7a12cb2333c0de0e23b610e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page