Skip to main content

EU captcha protects your website/API against abuse like form spam and credential stuffing

Reason this release was yanked:

testpypi-version

Project description

myra-eucaptcha

EU captcha protects your website/API against abuse like form spam and credential stuffing. This package provides server-side verification client for Myra EU Captcha.

Installation

Installation is performed via the regular PyPi-Repos with pip install myra-eucaptcha or uv add myra-eucaptcha, if you're using the uv package manager.

Integration

Frontend

There are only two snippets which need to be included in your page to enable captcha-validation. This is used to render the captcha and must be placed inside the form you want to protect.

<div class="eu-captcha" data-sitekey="YOUR_MYRA_EUCAPTCHA_SITEKEY"></div>

This includes the javascript-part of the captcha, which handles the actual captcha and transmits captcha data to Myra EU Captcha, updates the displayed Captcha HTML Snippets and adds data to your form.

<script src="https://cdn.eu-captcha.eu/verify.js" async defer></script>

Here is a functional, minimalistic example what your page could look like.

    <html>
        <head>
            <title>captcha integration sample</title>
        </head>
        <body>
    
        <form action="/login" method="post">
            <table>
                <tr>
                    <td>user</td>
                    <td>
                        <input type=text name="username" />
                    </td>
                </tr>
                <tr>
                    <td>pass</td>
                    <td>
                        <input type=password name="password" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="eu-captcha" data-sitekey="YOUR_MYRA_EUCAPTCHA_SITEKEY"></div>
                    </td>
                </tr>
                <tr><td colspan="2"><input type="submit" name="submit" /></td></tr>
            </table>
        </form>
        
        <script src="https://cdn.eu-captcha.eu/verify.js" async defer></script>
        </body>
    </html>

FastAPI Backend Example

This is the respective backend counterpart for the example-form from above. The library provides async and sync interfaces via .avalidate() and .validate() respectively.

from myra_eucaptcha import MyraEuCaptchaClient, MyraEuCaptchaClientConfig

@app.post("/login", response_class=HTMLResponse)
async def login(
    request:Request,
    username: str = Form(...),
    password: str = Form(...),
    eu_captcha_response: str = Form(..., alias="eu-captcha-response"),
):

    # configure the captcha settings and behaviour
    captcha_config = MyraEuCaptchaClientConfig(
        sitekey="YOUR_MYRA_EUCAPTCHA_SITEKEY",
        secret="YOUR_MYRA_EUCAPTCHA_SECRET",
    )

    client = MyraEuCaptchaClient(config=captcha_config)

    # this is depending on your webserver-setup and whether we're behind
    # a reverse-proxy (nginx, apache, traefik, or something similar.)
    remote_addr = request.headers.get('x-real-ip','')
    validationresult = await client.avalidate(
                token=eu_captcha_response,
                remote_addr=remote_addr)

    if validationresult.success:
        # yay - all good.
        # <your-code-here>
        pass
    else:
        # validation failed, check validationresult.errors
        # <your-code-here>
        pass

Design Decisions

The default mode of operation for EU Captcha is permissive and fault-tolerant. This means, that - should any error occur on the backend side during the communication of your server and Myra EU Captcha (timeouts, api-errors, network-errors or similar), the validation result will be True and no exceptions will be thrown. The exceptions will however be available in the MyraEuCaptchaResult.errors you receive.

This behaviour can be configured, by adapting MyraEuCaptchaClientConfig:

    captcha_config = MyraEuCaptchaClientConfig(
        sitekey="YOUR_MYRA_EUCAPTCHA_SITEKEY",
        secret="YOUR_MYRA_EUCAPTCHA_SECRET",
        connect_timeout: int = 3
        read_timeout: int = 10
        write_timeout: int = 10
        pool_timeout: int = 3
        default_result_on_error:bool = True ## this is the validation result, that is returned on exceptions
        suppress_exceptions:bool = True     ## if you want exceptions to be raised, set this to False
    )

Documentation

All documentation regarding non-functional changes, especially integration examples for other frameworks, will be provided and maintained under https://docs.eu-captcha.eu Functional changes will be documented in this package with a new release.

Download files

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

Source Distribution

myra_eucaptcha-0.1.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

myra_eucaptcha-0.1.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file myra_eucaptcha-0.1.1.tar.gz.

File metadata

  • Download URL: myra_eucaptcha-0.1.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for myra_eucaptcha-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ac38261b138c6c57bcdf0b2ae284f351856201d2ff8d4ff6f2f574849a68b652
MD5 94a06befa5a770acaf9cd0c6e0c78d3d
BLAKE2b-256 3d943fce8302902f047545974e5c5c923639396e8ddf8d4debf2635c1bfb8dfd

See more details on using hashes here.

File details

Details for the file myra_eucaptcha-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: myra_eucaptcha-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for myra_eucaptcha-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7867272df9146f3ee35263c3e9a895c40ef0aebe1bb502e643810be11d15a5d
MD5 4db319abda40d98d69b2606172718a1f
BLAKE2b-256 3adef3822a9502649fe80a9232b576b2bdb556a4f8730b896bee86704f064781

See more details on using hashes here.

Supported by

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