Python Flask
Follow these steps to implement Kable within your Python Flask API.
Estimated completion: 10 minutes
Get the latest version or contribute at:
Flask vs Django
If you are not using Kable as an Authentication Provider, then it does not matter if you use the Flask or Django SDK. The only differences between these two libraries is in the way headers are read for authentication purposes in
authenticate
.
Install dependencies
First, install the Kable Python Flask SDK using pip.
python3 -m pip install kable-python-flask
Implement Kable
from flask import Flask, jsonify
from kable_python_flask import Kable
app = Flask(__name__)
# Initialize Kable with fields found on your Company page in the dashboard
kable = Kable({
'kable_client_id': '<YOUR_KABLE_CLIENT_ID>',
'kable_client_secret': '<YOUR_KABLE_CLIENT_SECRET>',
'base_url': 'https://test.kable.io',
'debug': True,
})
@app.get('/api/record')
def get_record():
# record data from within your API
kable.record("yourcompanyuser_1234567890", { "userId": "xyz123" })
return jsonify({ 'message': 'Data has been recorded by Kable!' })
# for using Kable as an authentication provider
@app.get('/api/authenticate')
@kable.authenticate
def get_authenticate():
return jsonify({ 'message': 'This request has been authenticated and recorded by Kable!' })
Updated 7 months ago