Flask ServerΒΆ

The following example shows how to set up a simple Flask server for which we receive HTTP Post requests forwarded by a Data Connector. Contained within each request is event data from your sensors, and the request is validated and decoded using functions provided by this package.

import os
from flask import Flask, request  # pip install flask

from dtintegrations import data_connector, provider

app = Flask(__name__)


@app.route('/', methods=['POST'])
def print_request_contents():
    # Use the provider-specific validation function.
    payload = data_connector.HttpPush.from_provider(
        request=request,
        provider=provider.FLASK,
        secret=os.getenv('DT_SIGNATURE_SECRET'),
    )

    # Print the payload data.
    print(payload)

    # If all is well, return 200 response.
    return 'Success'

For a more comprehensive guide, our developer documentation contains a guide on how to use this kind of code to integrate with Heroku and other popular serverless cloud environments.