This library offers the API client to communicate with mosparo to verify a submission.
With this Python library you can connect to a mosparo installation and verify the submitted data.
Install this library by using pip:
pip install mosparo
- Create a project in your mosparo installation
- Include the mosparo script in your form
<div id="mosparo-box"></div>
<script src="https://[URL]/build/mosparo-frontend.js" defer></script>
<script>
var m;
window.onload = function(){
m = new mosparo('mosparo-box', 'https://[URL]', '[UUID]', '[PUBLIC_KEY]', {loadCssResource: true});
};
</script>
- Include the library in your project
pip install mosparo
- After the form was submitted, verify the data before processing it
from mosparo import Client
api_client = Client(host, public_key, private_key)
your_post_data = {} # This needs to be filled with the post data
mosparo_submit_token = your_post_data['_mosparo_submitToken']
mosparo_validation_token = your_post_data['_mosparo_validationToken']
result = api_client.verify_submission(your_post_data, mosparo_submit_token, mosparo_validation_token)
if result.is_submittable():
# Send the email or process the data
pass
else:
# Show error message
pass
Create a new client object to use the API client.
from mosparo import Client
api_client = Client(host, public_key, private_key, verify_ssl)
Parameter | Type | Description |
---|---|---|
host | str | The host of the mosparo installation |
public_key | str | The public key of the mosparo project |
private_key | str | The private key of the mosparo project |
verify_ssl | bool | Set to False, if the SSL certificate should not be verified. |
To verify the form data, call verify_submission
with the form data in an array and the submit and validation tokens, which mosparo generated on the form initialization and the form data validation. The method will return a VerificationResult
object.
result = api_client.verify_submission(form_data, mosparo_submit_token, mosparo_validation_token)
Parameter | Type | Description |
---|---|---|
form_data | dict | The dictionary with all the submitted form data. |
mosparo_submit_token | str | The submit token which was generated by mosparo and submitted with the form data |
mosparo_validation_token | str | The validation token which mosparo generated after the validation and which was submitted with the form data |
FIELD_NOT_VERIFIED
: 'not-verified'FIELD_VALID
: 'valid'FIELD_INVALID
: 'invalid'
Returns True, if the form is submittable. This means that the verification was successful and the form data are valid.
Returns True, if mosparo determined the form as valid. The difference to is_submittable()
is, that this
is the original result from mosparo while is_submittable()
also checks if the verification was done correctly.
Returns an array with all verified field keys.
Returns the verification status of one field.
Returns True, if there were verification issues.
Returns an array with all verification issues.
To get the statistic data, grouped by date, call get_statistic_by_date
. The method accepts a time range in second 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) |
Return the number of valid submissions in the requested time range.
Return the number of spam submissions in the requested time range.
Return the numbers grouped by date.
mosparo Python API Client is open-sourced software licensed under the MIT License. Please see the LICENSE file for the full license.