Python Backend Server
Configure Project
- First install the library.
$ pip install dapi-python- Create a Dapi client instance with your App Secret.
from dapi import DapiClient
client = DapiClient(app_secret="YOUR_APP_SECRET")Configure SDK Server
- Follow the steps in Configure Project first in order to obtain and import the library.
- You can use the
handleSDKDapiRequestsfunction from theDapiClientinstance inside your endpoint. Our code will basically update the request to add your app'sappSecretto 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 handlerComplete SDK Server example
Here is a complete example of an SDK server with python and Flask.
- Install Flask
pip install flask dapi-python- 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)- Run the Flask app. The server will be running on
localhost:8080
export FLASK_APP=app.py
flask run -p 8080Updated 5 months ago