Manage sessions for Dundas.
Description
Dundas has a very complete REST API.
With completeness comes complexity, and this module will help you use the query in an easier way.
Why this module is useful
It currently does 3 things for you.
If you use dundas.Session within a context 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 same sessionId parameter. This module creates
shortcuts for you for get, post and delete, 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.
Installation
Simply with pip, from pypi:
python3 -m pip install pydundas
or, assuming you do not have permission to store the module globally:
python3 -m pip install --user pydundas
The 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.
Examples
You can see all the examples in one directory.
All the examples below assume a url, user and pwd variables.
Happy flow with context manager
with Session(user=user, pwd=pwd, url=url) as d:
print(d.get('Server').text)
Output (example):
[{"name":"winterfell","serverGroupId":1,"lastSeenTime":"2019-03-29T09:33:38.880327Z","__classType":"dundas.configuration.ServerInfo"}]
When the variable d comes out of scope, so outside the with statement, you will be
automagically logged out.
Read credentials from a yaml file
If you have a yaml file with a user, pwd and url key, then you can read it from pydundas:
user: arya
pwd: 'valar morghulis'
url: winterfell.got
from pydundas import creds_from_yaml
creds=creds_from_yaml('credentials.yaml')
with Session(**creds) as d:
print(d.get('Server').text)
Exception within the context manager are properly handled
with Session(user=user, pwd=pwd, url=url) as d:
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-7783f88894bd
API calls
Constant
Most constants can be used via their human-readable name.
from pydundas import Api, Session, creds_from_yaml
with Session(**creds_from_yaml('credentials.yaml')) as d:
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'))
Cube
You can warehouse a cube, and get some information about it:
with Session(**creds) as d:
api = Api(d)
capi = api.cube()
cube = capi.getByPath('Awesome Project', '/relevant/path')
cube = capi.getByPath('DP', '/CustomReports/2daysent/1mailing sendouts')
if cube is None:
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()
Health
You can run all checks, and fix the failing one:
with Session(**creds, loglevel='warn') as d:
api = Api(d)
hapi = api.health()
failings = hapi.check(allchecks=True)
print(failings)
for f in failings:
hapi.check([f], fix=True)
Notification
You can get a notification by its name and then run it.
napi = api.notification()
notif = napi.getExactName(name='Awesome notification')
if len(notif) != 1:
print("None or more than one notification with this name.")
sys.exit(1)
napi.run(notif[0]['id'])
Project
For example, to find the ID of a project:
from pydundas import Api, Session, creds_from_yaml
with Session(**creds_from_yaml('credentials.yaml')) as d:
api=Api(d)
project = a.project()
print(project.getProjectIdByName('DP'))
Develop
You can either use conda or virtualenv. 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 dependencies
make devinit
# Tests
make pep8
make unittest
# Build a package
make package
# Clean up everything
make purge
Metadata
Release files for pydundas 1.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydundas-1.6.1.tar.gz | 27.6 kB | Without provenance | Details for pydundas-1.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydundas-1.6.1-py3-none-any.whl | Python 3 | none | any | Details for pydundas-1.6.1-py3-none-any.whl |
Total release size: 63.8 kB
Release files / pydundas-1.6.1.tar.gz
| Download URL | pydundas-1.6.1.tar.gz |
|---|---|
| Size | 27.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bb47975e2c6014d8e6c7858471c66f0f317da1798bc43999fc8e1cf0a747742
|
|
BLAKE2b-256 checksum How to use checksums |
f23532e3bec377ae027db7f97395588c28f5b75b8a37f7d8bb23b912b085fe5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.4
|
Release files / pydundas-1.6.1-py3-none-any.whl
| Download URL | pydundas-1.6.1-py3-none-any.whl |
|---|---|
| Size | 36.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3d3374b8dac57d5464c2acc4af21c97c538b4f4e7490910a59efa880075bac9
|
|
BLAKE2b-256 checksum How to use checksums |
fad1bde8af40482d566d395ae63de990e3d94d9708673b7946409e437898a0d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.4
|
Security for pydundas 1.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.