Python Access Datatable

The Python programming language is often used in data science applications. This short example illustrates how to query a Buzzy Datatable from Python.

This example uses two Python libraries requests and json.

The flow of the code follows the microappdata tutorial:

  • login into buzzy with your credentials

  • query all of the microApp rows and print them

import requests
import json

credentials = { 
    "email":"my-email@buzzy.buzz",
	"password":"my-password"
}

loginResponse = requests.post("https://a.buzzy.buzz/api/login",data=credentials)
print('Log into Buzzy Server Status',loginResponse.status_code)

if (loginResponse.status_code == 200): 
    print('Log into Buzzy Server Response\n',loginResponse.text)
    rtext = json.loads(loginResponse.text)
    rdata = rtext["data"]
    authToken = rdata["authToken"]
    userId = rdata["userId"]
    print('authToken:', authToken)
    print('userId:', userId)

    headers = {'X-Auth-Token': authToken, 'X-User-Id' : userId }
    mID = {"microAppID" : "insert microapp id here"}

    appResponse = requests.post("https://a.buzzy.buzz/api/microappdata",headers=headers,data=mID)
    rtext = json.loads(appResponse.text)
    body = rtext["body"]
    microAppRows = body["microAppRows"]

    for row in microAppRows:
        print(row)

print("Done.")

Last updated