Package: pydundas
Manage sessions forDundas.DescriptionDundas has a very completeREST API.With completeness comes complexity, and this module will help you use the query in an
easier way.Why this module is usefulIt currently does 3 things for you.If you usedundas.Sessionwithin acontext manager,
the context manager wil log you in and out automagically, no matter what happens. You can
use the session object as a normal object as well as long as you do not forget to log in and out
yourself.Each and every call to the API needs to have the samesessionIdparameter. This module creates
shortcuts for you forget,postanddelete, to make your life easier. You do not need
to repeat the host, api path prefix or sessionId every single time.Some API calls are ported and might have helper methods. I am updating the module based on what I
need and use, so I do not expect to have everything ported on my own.InstallationSimply with pip, frompypi:python3-mpipinstallpydundasor, assuming you do not have permission to store the module globally:python3-mpipinstall--userpydundasThe module should be able to work with python2 as well, but it is untested and as python2 will be end of life'd in a few
months anyway I did not look into it.ExamplesYou can see all theexamplesin one directory.All the examples below assume aurl,userandpwdvariables.Happy flow with context managerwithSession(user=user,pwd=pwd,url=url)asd:print(d.get('Server').text)Output (example):[{"name":"winterfell","serverGroupId":1,"lastSeenTime":"2019-03-29T09:33:38.880327Z","__classType":"dundas.configuration.ServerInfo"}]When the variabledcomes out of scope, so outside thewithstatement, you will be
automagically logged out.Read credentials from a yaml fileIf you have a yaml file with auser,pwdandurlkey, then you can read it from pydundas:user:aryapwd:'valarmorghulis'url:winterfell.gotfrompydundasimportcreds_from_yamlcreds=creds_from_yaml('credentials.yaml')withSession(**creds)asd:print(d.get('Server').text)Exception within the context manager are properly handledwithSession(user=user,pwd=pwd,url=url)asd:d.get('you/know/nothing')output:404 Client Error: Not Found for url: https://winterfell.got/api/you/know/nothing?sessionId=fbeb7897-5981-412b-a981-7783f88894bdAPI callsConstantMost constants can be used via their human-readable name.frompydundasimportApi,Session,creds_from_yamlwithSession(**creds_from_yaml('credentials.yaml'))asd:a=Api(d)c=a.constant()# returns ['STANDARD_EXCEL_EXPORT_PROVIDER_ID']print(c.getNamesById('679e6337-48aa-4aa3-ad3d-db30ce943dc9'))# returns '679e6337-48aa-4aa3-ad3d-db30ce943dc9'print(c.getIdByName('STANDARD_EXCEL_EXPORT_PROVIDER_ID'))CubeYou can warehouse a cube, and get some information about it:withSession(**creds)asd:api=Api(d)capi=api.cube()cube=capi.getByPath('Awesome Project','/relevant/path')cube=capi.getByPath('DP','/CustomReports/2daysent/1mailing sendouts')ifcubeisNone:print("Gotcha, no cube named like that.")sys.exit(1)print(cube.json())print(cube.is_checked_out())cube.warehouse()print(cube.isWarehousing())cube.waitForWarehousingCompletion()HealthYou can run all checks, and fix the failing one:withSession(**creds,loglevel='warn')asd:api=Api(d)hapi=api.health()failings=hapi.check(allchecks=True)print(failings)forfinfailings:hapi.check([f],fix=True)NotificationYou can get a notification by its name and then run it.napi=api.notification()notif=napi.getExactName(name='Awesome notification')iflen(notif)!=1:print("None or more than one notification with this name.")sys.exit(1)napi.run(notif[0]['id'])ProjectFor example, to find the ID of a project:frompydundasimportApi,Session,creds_from_yamlwithSession(**creds_from_yaml('credentials.yaml'))asd:api=Api(d)project=a.project()print(project.getProjectIdByName('DP'))DevelopYou can either usecondaorvirtualenv. Most relevant commands are in the Makefile.
First edit the first line of the makefile to choose if you want to use conda or virtualenv.# Build an environment with all dependenciesmakedevinit# Testsmakepep8
makeunittest# Build a packagemakepackage# Clean up everythingmakepurge