Skip to main content

A Python SDK for handling FormSG webhooks.

Project description

FormSG Python SDK

PyPI version PyPI license PyPI pyversions PyPI status PyPI download total

This SDK provides convenient utilities for verifying FormSG webhooks and decrypting submissions in Python and Flask or Django.

Installation

pip install formsg

Usage

The SDK provides two main utility functions for handling FormSG webhook:

For convenience, the SDK implements a decrypt_django_request and decrypt_flask_request which returns the decrypted FormSG content from a Django/Flask request object directly.

Example with Flask

from formsg.flask import decrypt_flask_request

from flask import Flask
from flask import jsonify
from flask import request

app = Flask(__name__)


@app.route('/formsg_webhook', methods=['POST'])
def formsg_webhook():
    decrypted = decrypt_flask_request(
        request,
        secret_key='xxx',
        webhook_uri='https://xxx.ngrok.io/formsg_webhook',  # we use ngrok to test our webhooks locally
    )

    return jsonify(decrypted)
#end def


if __name__ == '__main__':
    app.run(debug=True)
#end if

Contributions

If you find any issues or would like to contribute improvements, please feel free to raise them in this repository directly.

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

formsg-0.1.8.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

formsg-0.1.8-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

Supported by

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