Friday, 14 January 2022

PowerSchool Python Queries

I have successfully set up the plugin I need in PowerSchool to query tables via Python as follows. I looked at the examples in the PowerSchool library documentation, but cannot successfully query a specific table (while applying any filters) with the same approaches. I can only get the entire table (when using the SQL query) or "HTTPError: 400 Client Error: Bad Request for url: ..." (when using params).

import powerschool
import pandas as pd

client_id =  'client id goes here'
client_secret = 'client secret goes here'
my_credentials = (client_id, client_secret)
host_name = 'host name goes here'
ps = powerschool.PowerSchool(host=host_name, auth=my_credentials)
st = ps.get_schema_table('students') 

# I have tried each of these and they all return the entire table
sql = '''SELECT * FROM STUDENTS WHERE last_name IN ('SMITH', 'JOHNSON')'''
params = {'last_name':'SMITH',
          'projection':'last_name'}

stData = st.query(**params)
df = pd.DataFrame.from_dict(stData)

stData2 = st.query(body=sql)
df = pd.DataFrame.from_dict(stData2)

Thanks in advance!



from PowerSchool Python Queries

No comments:

Post a Comment