A client for Friendly Captcha.
Project description
Friendly Captcha 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.
Installation
pip install friendly-captcha-client
Usage
Initialization
To start using the client:
from friendly_client import FriendlyCaptchaClient
client = FriendlyCaptchaClient(
api_key="YOUR_API_KEY",
sitekey="YOUR_SITEKEY"
)
Verifying a Captcha Response
- To verify a captcha response:
result: FriendlyCaptchaResult = client.verify_captcha_response("CAPTCHA_RESPONSE_HERE")
print(result.should_accept) # True
print(result.was_able_to_verify) # True
- Verify with bad configuration in non-strict (default) mode
client.set_siteverify_endpoint("https://incorrect.endpoint.com")
result: FriendlyCaptchaResult = client.verify_captcha_response("CAPTCHA_RESPONSE_HERE")
print(result.should_accept) # True
print(result.was_able_to_verify) # False
- Verify with bad configuration in strict (default) mode
client.strict = True
client.set_siteverify_endpoint("https://incorrect.endpoint.com")
result: FriendlyCaptchaResult = client.verify_captcha_response("CAPTCHA_RESPONSE_HERE")
print(result.should_accept) # False
print(result.was_able_to_verify) # False
Configuration
The client offers several configuration options:
- api_key: Your Friendly Captcha API key.
- sitekey: Your Friendly Captcha site key.
- 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_response
returns True regardless. By passingstrict=true
, it will be false instead: every response needs to be strictly verified. - siteverify_endpoint: (Optional) The endpoint URL for the site verification API.
- 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 requests_mock
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)
python -m pytest integration_tests
Contributing
Contributions are welcome! If you'd like to contribute to this project, please submit a pull request with your changes.
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
File details
Details for the file friendly_captcha_client-0.0.2.tar.gz
.
File metadata
- Download URL: friendly_captcha_client-0.0.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f635916a2d519924b590667c08ef4bcbfc8f76dae6597b82493cccfd881259e |
|
MD5 | 47e166f313c7e16ffe28b10fd3f994f9 |
|
BLAKE2b-256 | 8d7286b6586427ae7ea6b1b2aadcfd72745afee636de69fe39630928ce6c46df |
File details
Details for the file friendly_captcha_client-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: friendly_captcha_client-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4680aa1327e0a091bc866d603672d275b8a27e1255b1df0587498b67d8b7148f |
|
MD5 | 4255bdaa2b9795727ac79f0dae619893 |
|
BLAKE2b-256 | 3a69ef7669e2a03379666bcab7ab46942321461d098095d2f98f748ee11f5c12 |