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

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.2.tar.gz (3.5 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.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: formsg_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 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.2.tar.gz
Algorithm Hash digest
SHA256 29287b65f2a9a2d5a36733ece51e859d377debd1046f4c2406796db171d1f861
MD5 5053570e3e717d767e48b48d07479ad6
BLAKE2b-256 889469cdab2d379eb8fce87e4cd0269423913a5808776a2fa28918cd35ffe257

See more details on using hashes here.

File details

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

File metadata

  • Download URL: formsg_sdk-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 65f004031b32ecd051a930654fd4f85fbdac00b81c17adccabc8d5752a9f4048
MD5 f3975bba635e58797750941d4b7ec292
BLAKE2b-256 22c5159b5a931d1c1ebc3df8ef1691421dcbd874ecf4cb4313f86f470d885449

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