Waldur Python SDK
Waldur SDK is a thin Python wrapper for common REST operations.
It allows you to interact with the Waldur REST API directly from your Python code.
The SDK is provided as a Python module named waldur_api_client.
Installation
The Waldur SDK is available on PyPI as waldur-api-client and requires Python 3.9 or newer.
Install the version that matches your Waldur server, so that the client knows the same endpoints and fields:
1 2 3 | |
In order to perform operations, a user needs to create an instance of AuthenticatedClient class:
1 2 3 4 5 6 | |
This instance provides interface for further interaction with Waldur and will be used across examples in related documentation.
Calling an endpoint
Each endpoint is a module under waldur_api_client.api.<tag>, named after the endpoint's operation, for example
waldur_api_client.api.marketplace_resources.marketplace_resources_list. A module offers up to four functions:
sync(...)returns the parsed response: a model object, a list of them, orNone.sync_detailed(...)returns aResponsewithstatus_code,headers, rawcontentandparsed.asyncio(...)andasyncio_detailed(...)are theasyncversions of the two above.
Endpoints whose response has no body, such as most actions that only change state, have only
sync_detailed and asyncio_detailed. List endpoints also have sync_all and asyncio_all, which follow the
pagination and return every page.
The fields of returned objects are the attributes of the model classes in waldur_api_client.models.
Error handling
If the API returns a status code that the endpoint does not document, for example 400 for invalid input or 403
for missing permissions, the SDK raises UnexpectedStatus. The exception carries the status code, the raw response
content and the URL.
1 2 3 4 5 6 7 8 | |
sync_detailed raises UnexpectedStatus in the same cases. Use it when a successful call needs more than the
parsed body, for example the response headers or the raw content:
1 2 3 4 5 | |
Disabling TLS validation (not recommended!)
If you are running your commands against Waldur deployment with broken TLS certificates (e.g. in development), the trick below can be used to disable validation of certificates by SDK, beware that this is a security risk.
1 2 3 4 5 6 7 | |
Sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
1 2 3 4 5 6 7 | |
Air gapped installation
If your machine from where you run SDK is not connected to the public Internet, you can use the following method to transfer required libraries.
On a machine with access to the Internet and the same Python version and platform, download the client and its dependencies:
1 2 3 | |
Now transfer content of the dependencies folder and requirements.txt to a machine without public Internet and run.
1 | |