Changelog

Python Backend Server

Configure Project

  1. First install the library.
$ pip install dapi-python
  1. Create a Dapi client instance with your App Secret.
from dapi import DapiClient

client = DapiClient(app_secret="YOUR_APP_SECRET")

Configure SDK Server

  1. Follow the steps in Configure Project first in order to obtain and import the library.
  2. You can use the handleSDKDapiRequests function from the DapiClient instance inside your endpoint. Our code will basically update the request to add your app's appSecret to it, and forward the request to Dapi, then return the result.
from dapi import DapiClient

client = DapiClient(app_secret="YOUR_APP_SECRET")

dapi_resp = client.handleSDKDapiRequests()  # inside your endpoint handler

Complete SDK Server example

Here is a complete example of an SDK server with python and Flask.

  1. Install Flask
pip install flask dapi-python
  1. Copy the code a file named app.py
from flask import Flask, request
from dapi import DapiClient

app = Flask(__name__)
client = DapiClient(app_secret="YOUR_APP_SECRET")

# The default route is just to check that the server is up. You can remove this.
@app.route('/')
def default_page():
    return "The SDK Server is working!"

@app.route('/handleSDK', methods=["POST"])
def sdk_handler():
    data = request.json
    headers = request.headers
    return client.handleSDKDapiRequests(data, headers)
  1. Run the Flask app. The server will be running on localhost:8080
export FLASK_APP=app.py
flask run -p 8080