Package: pyquo
Aboutpyquo is a library which offers bindings for the quolab REST API in
python.Compatibilitypyquo is designed to be compatbile with both python2 and python3Installation$pipinstallpyquoAuthenticationThere are two ways of authenticating against Quolab's API. The first
method is using the UserAuthenticator which usesBasicAuth.frompyquo.authenticatorimportUserAuthenticatorauth=UserAuthenticator(username='user',password='pass')However, the prefered way of authenticating would be by using theTokenAuthenticator.frompyquo.authenticatorimportTokenAuthenticatorauth=TokenAuthenticator(token='your-token-here')In order to generate a token the following pyquo code can be used:frompyquo.SessionimportSessionfrompyquo.authenticatorimportUserAuthenticator,TokenAuthenticatorsession=Session(base_url="https://qlab.quo/",global_session=True,auth=UserAuthenticator(username="<username>",password="<password>"))print(TokenAuthenticator.create_token(session,"1y"))For more information on theexpires_in(e.g. 1y = 1 year) field, please
consult the quolab REST API documentationSessionsIn order to interact with the quolab api, aSessioninstance is required. This
can be created as follows:frompyquo.sessionimportSessions=Session(base_url="https://<url>/",global_session=True,auth=auth,verify=False)When interacting with a single quolab instance, it is recommended to setglobal_sessiontoTrue. When interacting with multiple sessions at once,
e.g. retreiving information mutliple nodes, you will be required to store the
session, and pass it around with your queries.Modelspyquo implements (sys-)facts, (sys-)references and annotations as pyquo.model
object instances. For example, a case model can be created as follows:[In:]frompyquo.modelsimportCase[In:]case=Case(id='2981693283194043a185c0cc9412ad83')[Out:]case(2981693283194043a185c0cc9412ad83)caseis a 'handle' object for the case with the case id
'2981693283194043a185c0cc9412ad83'. This handle can now be used to perform
read/store/update/delete operations on the case.[In:]case.get()[In:]case.name[Out:]"Fancy case name"[In:]case.name="Renamed case"[In:]case.save()[In:]case.get().name[Out:]"Renamed case"QuerysetsReferences / Sysreferences(Sys-)Facts can have incoming and outgoing (sys-)references, which can be
queried as follows:[In:]references=case.references()[Out:][case(2981693283194043a185c0cc9412ad83)→associated-with→user(test),case(2981693283194043a185c0cc9412ad83)→encases→ipynb(Untitled1.ipynb)]This will show all outgoing references. In order to show incoming references,
theincomingparameter needs to be set toTrue(case.references(incoming=True))It is possible to filter forsysrefsusingfact.references(refs=SysRef).Further the associated facts behind the references can be filtered (e.g. Files
and Mutexes only) using:[In:]fact.references(facts=(models.File,models.Mutex))While the reference type can also be filtered using:[In:]fact.references[models.Contains](facts=(models.File,models.Mutex))The obtained references have asourceand atargetproperty which resolves
to an instance of the related fact. E.g.[In:]reference[Out:]case(2981693283194043a185c0cc9412ad83)→encases→ipynb(Untitled1.ipynb)[In:]reference.source[Out:]case(2981693283194043a185c0cc9412ad83)[In:]reference.target[Out:]ipynb(Untitled1.ipynb)It is also possible to obtain thesourceandtargetfacts directly, by
using the propertiesfact.ancestorsandfact.descendants.AnnotationsFact annotations can be queries as follows:fact.annotations(annotations=pyquo.models.KnownAs,limit=3)annotations=<pyquo.Model>allows serverside filtering for annotations of a
given type, whilelimit=1allows limiting the number of results returned by a
given query.Raw QueriesFrom time to time it can occur that pyquo is not flexible enough to cover each
and every usecase/api feature which is why raw queries have been made possible
in pyquo:frompyquo.sessionimportQueryfoo={"class":"annotation","type":"known-as","aggregate":"first","fact":{"type":"function","id":[f.idforfinfunctions],"aggregate":"group"}}foriinQuery.generate(foo,session):print(i)print(Query.execute(foo,session))TheQuery.generate(foo, session)method will execute the given query and
return a deserialized pyquo object, whileresult = Query.execute(foo, session)will return the raw query result as a dictionary.ExamplesFurhter examples can be found hereExample.md