Skip to main content

Utility to download or upload data from/to .Stat Suite using ADFS authentication to connect to it

Project description

DotStat_IO package:

A generic python package which could be integrated with other end-user applications and Gitlab runner to perform basic io with .Stat Suite. Its role is to mask the complexities of authentication to connect to .Stat Suite. The user needs to provide a set of parameters and the package exposes a couple of methods which will download or upload data from/to .Stat Suite.

This package contains three modules:

  • ADFSAuthentication module
  • KeycloakAuthentication module
  • Client module

In ADFSAuthentication module, four methods are available:

1. To initialise the module for interactive use:

from dotstat_io.authentication import AdfsAuthentication
interactive_obj = AdfsAuthentication.interactive(
        client_id=client_id,
        sdmx_resource_id=sdmx_resource_id,
        scopes=scopes,
        authority_url=authority_url,
        redirect_port=redirect_port)
  • client_id: The Application (client) ID that the ADFS assigned to your app
  • sdmx_resource_id: The ID of the application to be accessed such as .Stat Suite
  • scopes: Scopes requested to access a protected API (a resource defined by sdmx_resource_id)
  • authority_url: URL that identifies a token authority
  • redirect_port: The port of the address to return to upon receiving a response from the authority

2. To initialise the module for non-interactive use using a secret:

from dotstat_io.authentication import AdfsAuthentication
noninteractive_with_secret_obj = AdfsAuthentication.noninteractive_with_secret(
        client_id=client_id,
        sdmx_resource_id=sdmx_resource_id,
        scopes=scopes,
        authority_url=authority_url,
        client_secret=client_secret)
  • client_id: The Application (client) ID that the ADFS assigned to your app
  • sdmx_resource_id: The ID of the application to be accessed such as .Stat Suite
  • scopes: Scopes requested to access a protected API (a resource defined by sdmx_resource_id)
  • authority_url: URL that identifies a token authority
  • client_secret: The application secret that you created during app registration in ADFS

3. To initialise the module for non-interactive use using windows client authentication:

from dotstat_io.authentication import AdfsAuthentication
noninteractive_with_adfs_obj = AdfsAuthentication.noninteractive_with_adfs(
        client_id=client_id,
        sdmx_resource_id=sdmx_resource_id,
        token_url=token_url)
  • client_id: The Application (client) ID that the ADFS assigned to your app
  • sdmx_resource_id: The ID of the application to be accessed such as .Stat Suite
  • token_url: URL of the authentication service

4. To get a token after initialisation of "AdfsAuthentication" object as shown above:

access_token = [Authentication Object Name].get_token()

In KeycloakAuthentication module, two methods are available:

1. To initialise the module for Keycloak authentication:

from dotstat_io.authentication import KeycloakAuthentication
noninteractive_with_keycloak_obj = KeycloakAuthentication.noninteractive_with_secret(
        user=user,
        password=password, 
        token_url=token_url, 
        proxy=proxy)
  • user: User name for .Stat Suite authentication
  • password: User name's password
  • token_url: URL of the authentication service
  • proxy: URL of the SSL certificates

2. To get a token after initialisation of "KeycloakAuthentication" object as shown above:

access_token = [Authentication Object Name].get_token()

In Client module, six methods are available:

1. To initialise the module using an Authentication object type AdfsAuthentication or KeycloakAuthentication:

from dotstat_io.client import Client
client_obj = Client.init_with_authentication_obj(Authentication_obj)
  • Authentication_obj: An initialized authentication object type AdfsAuthentication or KeycloakAuthentication

2. To initialise the module using an access token:

from dotstat_io.client import Client
client_obj = Client.init_with_access_token(access_token)
  • access_token: An access token to make requests on .Stat Suite services (nsiws) using the authorisation service and underlying permission rules

3. To download a file from .Stat Suite:

from dotstat_io.client import Client
client_obj = Client.init_with_authentication_obj(Authentication_obj)
returned_result = client_obj.download_data_file(
        dotstat_url, content_format, Path(file_path))
  • dotstat_url: URL of data to be downloaded from .Stat Suite
  • content_format: Format of the downloaded content
  • file_path: The full path where the file will downloaded

4. To download streamed content from .Stat Suite:

from dotstat_io.client import Client
client_obj = Client.init_with_authentication_obj(Authentication_obj)
returned_result = client_obj.download_data_stream(
        dotstat_url, content_format)
  • dotstat_url: URL of data to be downloaded from .Stat Suite
  • content_format: Format of the downloaded content

5. To upload a data file to .Stat Suite:

from dotstat_io.client import Client
client_obj = Client.init_with_authentication_obj(Authentication_obj)
returned_result = client_obj.upload_data_file(
        transfer_url, Path(file_path), space, validationType, use_filepath)
  • transfer_url: URL of the transfer service
  • file_path: The full path of the SDMX-CSV file, which will be uploaded to .Stat Suite
  • space: Data space where the file will be uploaded
  • validationType: The type of validation to use during upload. Possible values: Basic Validation (0), Advanced Validation (1)
  • use_filepath: Use a file path of a shared folder accessible by the .Stat Suite data upload engine (for unlimited file sizes)

6. To upload a structure to .Stat Suite:

from dotstat_io.client import Client
client_obj = Client.init_with_authentication_obj(Authentication_obj)
returned_result = client_obj.upload_structure(
        transfer_url, Path(file_path))
  • transfer_url: URL of the transfer service
  • file_path: The full path of the SDMX-ML file, which will be uploaded to .Stat Suite

For more information about how to use this package, all test cases can be accessed from this link

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotstat_io-1.0.2.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dotstat_io-1.0.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file dotstat_io-1.0.2.tar.gz.

File metadata

  • Download URL: dotstat_io-1.0.2.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Windows/11

File hashes

Hashes for dotstat_io-1.0.2.tar.gz
Algorithm Hash digest
SHA256 93da57b6b003aeedac00af7de6a27dc7be1be2f8851c48fed706994b853e3e45
MD5 3a835985e99fbb849a7e1cebcfe579e1
BLAKE2b-256 1283ee787daf82227682a67a2c2d4fcbbcfde3db1368cae786df617440747a2b

See more details on using hashes here.

File details

Details for the file dotstat_io-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: dotstat_io-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Windows/11

File hashes

Hashes for dotstat_io-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dc7eb9b290d4e85611e7db04356d682d25b652d3b60ccc7f8a4361f1ea380c17
MD5 21cc6b8271497b0138de73fb619a6c25
BLAKE2b-256 f3e8f4a2e1cae2579e29e02b98f2d8a48aa8ca665fd0bafcbc5f1f5873f2dc44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page