Skip to main content

Python SDK for FormSG

Project description

Please note that this is an SDK for webhooks integration, and not the FormSG system.

FormSG Python3 SDK

This SDK provides convenient utilities for verifying FormSG webhooks and decrypting submissions in JavaScript and Node.js.

Installation

Install the package with

pip install formsg-sdk

Usage

Quickstart usage with Flask:

import os
import formsg
from flask import Flask, request

#get your FormSG's secret key from environment
FORM_SECRET_KEY = os.getenv('FORM_SECRET_KEY')

@app.route('/formsgtest',methods=['POST'])
def formsgtest():
    data = formsg.decrypt_responses(request, FORM_SECRET_KEY,securehttp=True)
    print(data)
	#display the decrypted data received
	
	#do your processing here
	
    return data

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

Webhook Authentication and Decrypting form responses

End-to-end Encryption

FormSG uses end-to-end encryption with elliptic curve cryptography to protect submission data and ensure only intended recipients are able to view form submissions. As such, FormSG servers are unable to access the data.

The underlying cryptosystem is x25519-xsalsa20-poly1305. This codebase is the python implementation of the NaCl library. Official webhook SDK by the FormSG team only supports javascript.

Format of Submission Response

Key Type Description
formId string Unique form identifier.
submissionId string Unique response identifier, displayed as 'Response ID' to form respondents
encryptedContent string The encrypted submission in base64.
created string Creation timestamp.
attachmentDownloadUrls Record<string, string> (Optional) Records containing field IDs and URLs where encrypted uploaded attachments can be downloaded.

Format of Decrypted Submissions

decrypt_responses(request, formSecretKey, securehttp=True) takes in a http request, formsecretkey (b64 encoded) and returns a dictionary with the following structure

{
'data': 
    {
    'formId': str
    'submissionId': str
    'version': str
    'created': str
    'attachmentDownloadUrls': dict
    'decryptedContent': [   
                        {
                        '_id': str
                        'question': str
                        'answer': str
                        'fieldtype': str
                            },
                            {
                        '_id': str
                        'question': str
                        'answer': str
                        'fieldtype': str
                        },
                            ...
                        ]
    }
}

Signature verification

Under the hood, signatures are verified upon decryption, using steps found here - Verifying Signatures Manually

TODO

Attachment decryption.

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_sdk-0.1.4.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

formsg_sdk-0.1.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file formsg_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: formsg_sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for formsg_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 81f08b45cefece72c8b0c24936d0664c7e2caba2aece1249814273f1da9e961e
MD5 f534be794cd09d0cf05f484ee394b9e7
BLAKE2b-256 c1b4203890cbddefd669d7946746430cebbc3eb124001e2d25a50165ef5ce4b2

See more details on using hashes here.

File details

Details for the file formsg_sdk-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: formsg_sdk-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for formsg_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2bec3024ef056fa61ec10212bbd3dcf76fa80bc9ceaeb85520a3666ad587f3ed
MD5 6d058cb956d6c57765d29d9865433b10
BLAKE2b-256 ac91c8b2a6b42882b6181cd83de9411b7206a34308c54c15e5524ba446f8eccb

See more details on using hashes here.

Supported by

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