Python API Client to communicate with kzCaptcha.
Project description
KzCaptcha - Python API Client
This library offers the API client to communicate with kuantaz to verify a submission.
Description
This Python library lets you connect to a kuantaz installation and verify the submitted data.
Installation
Install using pip
Install this library by using pip:
pip install kuantaz-api-client
Usage
- Create a project in your kuantaz installation
- Include the kuantaz script in your form
<div id="kuantaz-box"></div>
<script src="https://[URL]/build/kuantaz-frontend.js" defer></script>
<script>
var kz;
window.onload = function () {
kz = new kzCaptcha("kuantaz-box", "https://[URL]", "[UUID]", "[PUBLIC_KEY]");
};
</script>
- Include the library in your project
pip install kuantaz-api-client
- After the form is submitted, verify the data before processing it
from kuantaz_api_client import Client
api_client = Client(host, public_key, private_key)
your_post_data = {} # This needs to be filled with the post data
kuantaz_submit_token = your_post_data['_kuantaz_submitToken']
kuantaz_validation_token = your_post_data['_kuantaz_validationToken']
result = api_client.verify_submission(your_post_data, kuantaz_submit_token, kuantaz_validation_token)
if result.is_submittable():
# Send the email or process the data
pass
else:
# Show error message
pass
API Documentation
Client
Client initialization
Create a new client object to use the API client.
from kuantaz_api_client import Client
api_client = Client(host, public_key, private_key, verify_ssl)
| Parameter | Type | Description |
|---|---|---|
| host | str | The host of the kuantaz installation |
| public_key | str | The public key of the kuantaz project |
| private_key | str | The private key of the kuantaz project |
| verify_ssl | bool | Set to False if the SSL certificate should not be verified. |
Verify form data
To verify the form data, call verify_submission with the form data in an array and the submit and validation tokens, which kuantaz generated on the form initialization and the form data validation. The method will return a VerificationResult object.
result = api_client.verify_submission(form_data, kuantaz_submit_token, kuantaz_validation_token)
| Parameter | Type | Description |
|---|---|---|
| form_data | dict | The dictionary with all the submitted form data. |
| kuantaz_submit_token | str | The submit token which was generated by kuantaz and submitted with the form data |
| kuantaz_validation_token | str | The validation token which kuantaz generated after the validation and which was submitted with the form data |
VerificationResult
Constants
FIELD_NOT_VERIFIED: 'not-verified'FIELD_VALID: 'valid'FIELD_INVALID: 'invalid'
is_submittable(): bool
Returns True if the form is submittable. This means that the verification was successful and the
form data are valid.
is_valid(): bool
Returns True if kuantaz determined the form as valid. The difference to is_submittable() is, that this
is the original result from kuantaz, while is_submittable() also checks if the verification was done correctly.
get_verified_fields(): list (see Constants)
Returns an array with all verified field keys.
get_verified_field(key): string (see Constants)
Returns the verification status of one field.
has_issues(): bool
Returns True if there were verification issues.
get_issues(): list
Returns an array with all verification issues.
Get the statistic data by date
To get the statistic data grouped by date, call get_statistic_by_date. The method accepts a time range in seconds for which the data should be returned (last x seconds). The method will return a StatisticResult object.
result = api_client.get_statistic_by_date(range)
| Parameter | Type | Description |
|---|---|---|
| range | int | The time range in seconds for which the statistic should be returned (last X seconds) |
StatisticResult
get_number_of_valid_submissions(): int
Return the number of valid submissions in the requested time range.
get_number_of_spam_submissions(): int
Return the number of spam submissions in the requested time range.
get_numbers_by_date(): dict
Return the numbers grouped by date.
Project details
Release history Release notifications | RSS feed
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 kuantaz_api_client-1.0.1.tar.gz.
File metadata
- Download URL: kuantaz_api_client-1.0.1.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
188d229646e3caee7418cc30ea664cdffaeec6555dd14c363c7d169631019228
|
|
| MD5 |
4b1a634df0a7e61d773723d9d60b19eb
|
|
| BLAKE2b-256 |
2fee705691d04fddad999730e669907cf9768d55f340feac5447ed1e7c72d3b1
|
File details
Details for the file kuantaz_api_client-1.0.1-py3-none-any.whl.
File metadata
- Download URL: kuantaz_api_client-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68b45cfdcc629d698b6994ea6adf3e019a31b12d1f6d7528c8cb36df762a3248
|
|
| MD5 |
1a379412481208b88a277eff2d7dfa09
|
|
| BLAKE2b-256 |
692f66abe6634a51516361d02a05355b08d0b699e273bd0c5111cdcac8746395
|