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():
    kable.record({ "clientId": "yourcompanyuser_1234567890", "userId": "xyz123" })
    return jsonify({ 'message': 'Data has been recorded by Kable!' })

@app.get('/api/authenticate')
@kable.authenticate
def get_authenticate():
    return jsonify({ 'message': 'This request has been authenticated and recorded by Kable!' })

Did this page help you?