A client for Friendly Captcha.
Project description
Friendly Captcha Python SDK
A Python client for the Friendly Captcha service. This client allows for easy integration and verification of captcha responses with the Friendly Captcha API.
This library is for Friendly Captcha V2 only. If you are looking for V1, look here
Installation
pip install friendly-captcha-client
Usage
Below are some basic examples of how to use the client.
For a more detailed example, take a look at the example directory.
Initialization
To start using the client:
from friendly_captcha_client.client import FriendlyCaptchaClient
client = FriendlyCaptchaClient(
api_key="YOUR_API_KEY",
sitekey="YOUR_SITEKEY"
)
Verifying a Captcha Response
After calling verify_captcha_response with the captcha response there are two functions on the result object that you should check:
was_able_to_verifyindicates whether we were able to verify the captcha response. This will beFalsein case there was an issue with the network/our service or if there was a mistake in the configuration.should_acceptindicates whether the captcha response was correct. If the client is running in non-strict mode (default) andwas_able_to_verifyreturnedFalse, this will beTrue.
Below are some examples of this behaviour.
Verifying a correct captcha response without issues when veryfing:
result = client.verify_captcha_response("CORRECT?CAPTCHA_RESPONSE_HERE")
print(result.was_able_to_verify) # True
print(result.should_accept) # True
Verifying an incorrect captcha response without issues when veryfing:
result = client.verify_captcha_response("INCORRECT_CAPTCHA_RESPONSE_HERE")
print(result.was_able_to_verify) # True
print(result.should_accept) # False
Verifying an incorrect captcha response with issues (network issues or bad configuration) when veryfing in non-strict mode (default):
result = client.verify_captcha_response("INCORRECT_CAPTCHA_RESPONSE_HERE")
print(result.was_able_to_verify) # False
print(result.should_accept) # True
Verifying an incorrect captcha response with issues (network/service issues or bad configuration) when veryfing in strict mode:
client.strict = True
result = client.verify_captcha_response("INCORRECT_CAPTCHA_RESPONSE_HERE")
print(result.should_accept) # False
print(result.was_able_to_verify) # False
Risk Intelligence Data Retrieval
Use retrieve_risk_intelligence to retrieve risk intelligence data from a token.
result = client.retrieve_risk_intelligence("RISK_INTELLIGENCE_TOKEN_HERE")
if not result.was_able_to_retrieve:
# handle request/client error, inspect result.error
return
if not result.is_valid:
# handle invalid token, inspect result.error
return
print(result.data.risk_intelligence) # The risk intelligence data
Configuration
The client offers several configuration options:
- api_key: Your Friendly Captcha API key.
- sitekey: (Optional) Your Friendly Captcha sitekey. Configure this if you want to ensure that a captcha solution or risk intelligence token was generated from a specific sitekey.
- strict: (Optional) In case the client was not able to verify the captcha response at all (for example if there is a network failure or a mistake in configuration), by default the
verify_captcha_responsereturnsTrueregardless. By passingstrict=True, it will returnFalseinstead: every response needs to be strictly verified. - api_endpoint: (Optional) Base API endpoint (for example
https://eu.frcapi.com). Shorthandseuorglobalare also accepted. Default isglobal. - siteverify_endpoint: (Optional,Deprecated) Kept for backwards compatibility, use
api_endpointinstead. Accepts a full siteverify URL or shorthandseu/global; path is stripped and converted toapi_endpoint. - verbose: (Optional) Default is False. Turn on basic logging.
- Error Handling: The client has built-in error handling mechanisms. In case of unexpected responses or errors from the Friendly Captcha API, the client will log the error and provide a default response.
Development
To install it locally:
pip install -e .
pip install -r requirements-dev.txt
Run the tests:
# Run the unit tests
python -m pytest
# Run the SDK integration tests (requires that you have the SDK test mock server running)
docker run -p 1090:1090 friendlycaptcha/sdk-testserver:latest
python -m pytest integration_tests
License
Open source under MIT.
Project details
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 friendly_captcha_client-0.2.0.tar.gz.
File metadata
- Download URL: friendly_captcha_client-0.2.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6441d8ca4aec1291cfd020c5c6e22c893e15aacddc17353982050e985d6c58f8
|
|
| MD5 |
0311ba3ad965edae2e69e7094f5c1198
|
|
| BLAKE2b-256 |
7418b11c23784f27b4a7db4e326929ffd6d688a553eb5fc69ea378d9ea216eb0
|
Provenance
The following attestation bundles were made for friendly_captcha_client-0.2.0.tar.gz:
Publisher:
publish.yml on FriendlyCaptcha/friendly-captcha-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
friendly_captcha_client-0.2.0.tar.gz -
Subject digest:
6441d8ca4aec1291cfd020c5c6e22c893e15aacddc17353982050e985d6c58f8 - Sigstore transparency entry: 1110095313
- Sigstore integration time:
-
Permalink:
FriendlyCaptcha/friendly-captcha-python@92fdbfa1f585eb155337a9b36abcbae88a4397f7 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/FriendlyCaptcha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@92fdbfa1f585eb155337a9b36abcbae88a4397f7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file friendly_captcha_client-0.2.0-py3-none-any.whl.
File metadata
- Download URL: friendly_captcha_client-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f1a780dd61bb3d7bb4d7b602c9266b4a674aa67df09578e4aa71c19f2077735
|
|
| MD5 |
16bd1410289b671d0e51264852a43446
|
|
| BLAKE2b-256 |
1d89764eb402b1d0ec2cc24ce3bcaabd5028fc438f26d7acd17bfbcf01d25cbb
|
Provenance
The following attestation bundles were made for friendly_captcha_client-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on FriendlyCaptcha/friendly-captcha-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
friendly_captcha_client-0.2.0-py3-none-any.whl -
Subject digest:
7f1a780dd61bb3d7bb4d7b602c9266b4a674aa67df09578e4aa71c19f2077735 - Sigstore transparency entry: 1110095317
- Sigstore integration time:
-
Permalink:
FriendlyCaptcha/friendly-captcha-python@92fdbfa1f585eb155337a9b36abcbae88a4397f7 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/FriendlyCaptcha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@92fdbfa1f585eb155337a9b36abcbae88a4397f7 -
Trigger Event:
release
-
Statement type: