qa4sm_api package

Submodules

qa4sm_api.cli module

qa4sm_api.cli.setup_api(instance='qa4sm.eu')[source]

Login to instance via username and password. Retrieve API token and store it in ~/.qa4smapirc for future use.

qa4sm_api.client_api module

class qa4sm_api.client_api.Access(access)[source]

Bases: object

classmethod from_available()[source]
classmethod from_dotrcfile(path=PosixPath('/home/runner/.qa4smapirc'))[source]

Load access from dotrc file.

Parameters:

path (str) – Path to the dotrc file

classmethod from_env()[source]
classmethod with_token(instance, token)[source]

Load access with token for a specific instance.

Parameters:
  • instance (str) – QA4SM instance name

  • token (str) – API token for the instance

Returns:

Access object with token

Return type:

Access

classmethod without_token(instance)[source]

Create access for instance without token (limited access).

Parameters:

instance (str) – QA4SM instance name

Returns:

Access object with None token (limited access)

Return type:

Access

class qa4sm_api.client_api.Connection(instance: str = 'qa4sm.eu', token='auto', protocol='https')[source]

Bases: object

Communication with QA4SM.

check_errors(validation_id)[source]

Check if the passed validation run has ended with an error

dataset_id(dataset: str) int[source]

Get dataset ID from short name.

Parameters:

dataset (str) – Dataset short name

Returns:

id – Dataset ID

Return type:

int

dataset_info(dataset: str | int) Series[source]

Get dataset metadata

Parameters:

dataset (str or int) – Dataset name or ID

Returns:

ser

Return type:

pd.Series

datasets() DataFrame[source]

Get a list of available datasets.

download_configuration(run_id, out_dir=None)[source]

Download validation configuration used for a specific run.

Parameters:
  • run_id (str) – UID of remote run to download configuration for

  • out_dir (str, optional) – To save the config as a .json file, pass the storage path

Returns:

config – Downloaded Configuration object

Return type:

ValidationConfiguration

download_results(run_id, out_dir, force_download=False)[source]

Download all results for a run

Parameters:
  • run_id (str) – UID of remote run to download results for

  • out_dir (str or Path) – Where the results are stored, will be created if it doesn’t exist yet.

  • force_download (bool, optional) – Always download, replace any existing local files. If False, only downloads results that don’t exist locally.

filter_info(filter_id)[source]

Get information about a data filter.

Parameters:

filter_id (int) – The ID of the data filter to get information for

Returns:

ds – Information about the data filter

Return type:

pd.Series

get_period(vers_id: int) -> (<class 'str'>, <class 'str'>)[source]

Get start and end date of selected dataset directly from the service

login(username, password)[source]
run_config_validation(config_path, override=None)[source]

Trigger validation run based on the passed config.

Parameters:
  • config_path (str) – Path to the config json to post.

  • override (dict, optional (default: None)) – keys and values to override settings in the configuration.

Returns:

response – Response from validation run (or config if dry_run is True)

Return type:

dict

run_validation(config)[source]

Trigger validation run based on the passed config.

Parameters:

config (ValidationConfiguration) – Validation configuration to send to the service

Returns:

response – Response from validation run

Return type:

pd.Series

url(*args, **kwargs) str[source]
user() Series[source]
validation_duration(validation_id: str) -> (<class 'int'>, <class 'str'>)[source]

Get the duration of a validation run in seconds and formatted string. This works for finished OR running validations

validation_exists(validation_id: str) bool[source]

Check if a validation run exists online (running or finished, not deleted).

validation_status(validation_id)[source]

Check if the passed validation run is still running, completed or is not found.

Parameters:

validation_id (str) – Hash of the remote validation run to check.

Returns:

  • status (str) –

    Status of the validation run. Can be one of:
    • ’NOT FOUND’: The validation id was not found

    • ’SCHEDULED’: The validation is queued

    • ’RUNNING’: The validation is still running

    • ’DONE’: The validation is completed

    • ’CANCELLED’: The validation was cancelled

    • ’ERROR’: The validation failed with an error

  • progress (int) – Progress of the validation run in percent (0-100).

validation_time(validation_id: str)[source]

Get start and end time when a validation run was processing. This works for finished OR running validations.

Returns:

start_time – None means that the validation was not started

Return type:

datetime or None

variable_info(var_id) Series[source]

Get information about a dataset variable.

Parameters:

var_id (int) – The ID of the dataset variable to get information for

Returns:

ds – Information about the dataset variable

Return type:

pd.Series

version_id(version, dataset)[source]

Get the version ID for a passed version name

Parameters:
  • version (str) – Version name

  • dataset (str or int) – Dataset id or short name

Returns:

version_id – Version ID

Return type:

int

version_info(version: str | int, dataset: str | int | None = None) Series[source]

Get version metadata

Parameters:
  • version (str or int) – Version name or ID.

  • dataset (str or int) – Dataset name or ID that the version belongs to. Only required when version is a string

Returns:

ser

Return type:

pd.Series

versions(ds) DataFrame[source]

Get the version information for a dataset.

Parameters:

ds (int or str) – The dataset index or short name to get versions for

Returns:

df – Version information for the chosen dataset

Return type:

pd.DataFrame

class qa4sm_api.client_api.Response(response, serialize=True)[source]

Bases: object

property data: List[dict]
property pandas: DataFrame | Series

Get all request return data as a DataFrame

class qa4sm_api.client_api.Session(instance='qa4sm.eu', token='auto', protocol='https')[source]

Bases: object

Wrapper to send API request to QA4SM after authentication.

get(url, *args, **kwargs) Response[source]

Send a GET request to the API.

Parameters:

url (str) – URL to send the request to

Returns:

Response from the API

Return type:

Response

login_with_credentials(username=None, password=None, quiet=False)[source]

Authenticate with username and password to receive a token for subsequent requests.

Parameters:
  • username (str) – Username for the chosen QA4SM instance.

  • password (str) – Password for the chosen QA4SM instance.

  • quiet (bool, optional (default: False)) – Suppress welcome message.

Returns:

token – user login token

Return type:

str

login_with_token(token, quiet=False) int[source]

status_code 200: OK, login successful

post(url, data, *args, **kwargs) Response[source]

Send a POST request to the API.

Parameters:
  • url (str) – URL to send the request to

  • data (dict) – Data to include in the request body

Returns:

Response from the API

Return type:

Response

url(*args) str[source]
class qa4sm_api.client_api.ValidationConfiguration(config_data: dict)[source]

Bases: object

dump(path)[source]

Dump the configuration to a new json file.

Parameters:

path (str or Path) – Path to json file to create

property empty
classmethod from_file(path)[source]

Load a configuration from a json file.

Parameters:

path (str or Path) – Path to the json file to load

classmethod from_remote(run_id, **connection_kwargs)[source]

Load a configuration from an existing remote run. Configs are public, so it’s not necessary to authenticate.

Parameters:
  • run_id (str) – UID of the validation run at the chosen instance (see connection_kwargs).

  • instance (str, optional (default: "qa4sm.eu")) – see qa4sm_api.client_api.Connection

  • token (str, optional) – see qa4sm_api.client_api.Connection

  • protocol (str, optional) – see qa4sm_api.client_api.Connection

qa4sm_api.globals module

exception qa4sm_api.globals.AuthenticationError(message='No API token is available for this user. Please generate one.')[source]

Bases: ValueError

exception qa4sm_api.globals.ValidationInstanceError(message='Unknown validation instance')[source]

Bases: KeyError

exception qa4sm_api.globals.ValidationRunError(message='Validation run failed')[source]

Bases: Exception

exception qa4sm_api.globals.ValidationRunNotFoundError(id)[source]

Bases: ValueError

Module contents