The Boa Python Client API provides programmatic access to the Boa language and infrastructure from Python.
For more information about Boa, please see the main website: https://boa.cs.iastate.edu/
The main entry point for the API is a BoaClient object. You use this to log in, submit queries, find datasets, log out, etc. To instantiate this object, you must provide the API endpoint's URL. The API has several constants for common endpoints:
BOA_API_ENDPOINT- for the Boa MSR endpointBOAC_API_ENDPOINT- for the Boa CORD-19 endpoint
For example if you want a client for the CORD-19 endpoint, you do the following:
client = BoaClient(endpoint=BOAC_API_ENDPOINT)
If you don't specify an endpoint, it will default to the MSR endpoint.
importgetpassimporttimefromboaapi.boa_clientimportBoaClient, BOA_API_ENDPOINTfromboaapi.statusimportCompilerStatus, ExecutionStatusclient=BoaClient(endpoint=BOA_API_ENDPOINT)
user=input("Username [%s]: "%getpass.getuser())
ifnotuser:
user=getpass.getuser()
client.login(user, getpass.getpass())
print('successfully logged in to Boa API')
query="""# Counting the 10 most used programming languagesp: Project = input;counts: output top(10) of string weight int;foreach (i: int; def(p.programming_languages[i])) counts << p.programming_languages[i] weight 1;"""# query using a specific datasetjob=client.query(query, client.get_dataset('2019 October/GitHub'))
print('query submitted')
whilejob.is_running():
job.refresh()
print('job '+str(job.id) +' still running, waiting 10s...')
time.sleep(10)
ifjob.compiler_statusisCompilerStatus.ERROR:
print('job '+str(job.id) +' had compile error')
elifjob.exec_statusisExecutionStatus.ERROR:
print('job '+str(job.id) +' had exec error')
else:
try:
print('output:')
print(job.output())
except:
passclient.close()
print('client closed')