SDK

Module containing the main class of the whole library. This is the class that users will be interacting with. It’s the main entrypoint for all other actions.

class sdk.DataStewardshipWizardSDK(session=None, http_client=None, logger=None, **kwargs)

This class provides simple and concise way to communicate with the Data Stewardship Wizard API. It offers both low-level and object-oriented interfaces.

Low-level API reflects exactly 1:1 the whole SDK API. For each endpoint and each HTTP method there’s a function on the low-level interface, which is accessible as the api attribute. This interface is intended for use cases which are not covered by the high-level API, offering 100% of the DSW’s functionality.

High-level object-oriented interface is available for the most common operations. It’s possible that new features will be added in the future. This interface is divided by the entities it is concerned with. Right now there are 6 interfaces of this kind, accessible via attributes:

  • app_config

  • documents

  • packages

  • questionnaires

  • templates

  • users

each containing it’s own set of functionality (but in most cases it’s just CRUD operations).

There some dependency injection parameters you can pass in order to alter the default behavior:

  • session – you can pre-configure your own session and pass it as the argument; it will be used with the HTTP client

  • http_client – either instance or class implementing the HttpClient interface. If you pass only the class, it will get instantiated with all the other config values and auth settings. This way you can override some aspects of the default HTTP client, but don’t have to initialize it yourself. But you can also pass the ready-to-use instance and all the HTTP client related config will be ignored.

  • logger – if you want, you can specify your own logger.

All configuration values can be set in 3 different ways:

  • passing as keyword arguments to the __init__() method

  • setting values as env variables (prefixed with DSW_SDK_)

  • via config file (in YAML format); path is passed in the conf_file keyword argument

Here is a list of all possible configuration values:

Keyword arguments
  • api_url (str): URL address of the DSW API you want to connect to. It must contain valid url scheme (e.g. https://) Mandatory if not passing your own http_client.

  • email (str): e-mail address of the user on whose behalf you will be acting. Mandatory if not passing your own http_client.

  • password (str): password for logging in. Mandatory if not passing your own http_client.

  • enable_ssl (bool): flag defining if the HTTP communication should be encrypted or not. Default: True.

  • auth_endpoint (str): endpoint on the DSW API that is responsible for the authorization. Default: '/tokens'.

  • headers (Dict[str, str]): Dict of default headers to be sent with every HTTP request. Default: {}.

  • default_timeout: This timeout is used as default value when no timeout is specified within a specific request. You can pass one numeric value (applied for both the connect and read timeouts), tuple of numeric values to specify different connect and read timeouts or None to wait forever. Default: (6.05, 27):

  • logger_name (str): Name of the default logger. Default: 'dsw_sdk'.

  • logger_level (Union[int, str]): Logging level of the default logger. You can use both string levels (e.g. 'INFO') or integer levels, ideally constants from the logging library (e.g. logging.INFO). Default: logging.WARNING.

  • logger_format (str): String describing the format of the default logger. For more info, consult the official Python docs about logging module. Default: [%(asctime)s] - %(name)s | %(levelname)s | %(message)s.

Parameters
  • session (requests.Session) –

  • http_client (HTTP_CLIENT) –

  • logger (logging.Logger) –

Example usage:

# Basic configuration
sdk = DataStewardshipWizardSDK(
    api_url='http://localhost:3000',
    email='albert.einstein@example.com',
    password='password',
)

# High-level API usage
temps = sdk.templates.get_templates(size=2, q='my templates')
for temp in temps:
    # Each `temp` is a `Template` instance
    print(template.usable_packages[0].version)
    temp.name = 'Modified template name'
    temp.save()
Parameters
  • session (requests.Session) – pre-configured session to be used with the HTTP client instead of the default one

  • http_client (HTTP_CLIENT) – instance or class implementing the HttpClient interface

  • logger (logging.Logger) – pre-configured logger to be used instead of the default one

sdk.HTTP_CLIENT

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Union[dsw_sdk.http_client.interface.HttpClient, Type[dsw_sdk.http_client.interface.HttpClient]]