Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The STACKIT SDK for Python

License

NotificationsYou must be signed in to change notification settings

stackitcloud/stackit-sdk-python

Repository files navigation

GitHub LicenseCI WorkflowCD WorkflowDependency-Updater

Note

The STACKIT Python SDK is in beta and in active development.

Overview

This repository contains the published Python SDKs and releases.The modules are structured into a core module with service clients, authentication and shared functionality as well as the different STACKIT services.The usage of the SDK is shown in some examples.

Getting started

The SDK is structured into several packages, each of them implementing the REST client for a service.To use a specific service, you can install it as:

pip install stackit-redis

It will install all needed dependencies automatically, so you can use the package right away.

Installation from source

In order to install the code from source you have to execute the following code:

pip install services/<service-name>

Where<service-name> has to be replaced by the name of the service you want to install.Forredis the command would be:

pip install services/redis

If you want to install all services you can use theMakefile with the following command:

make install

Examples

You can find several examples on how to use the SDK and also on how to configure the SDK to use your own custom implementation (to set proxies or implement a more fine-grained retry behaviour) in theexamples folder.

There are also several examples for each service to help you get started right away.The only thing you need is a STACKIT account and valid credentials.

Authorization

To authenticate to the SDK, you will need aservice account. Create it in the STACKIT Portal and assign it the necessary permissions, e.g.project.owner.

There are multiple ways to authenticate:

  • Key flow (recommended)
  • Token flow

When setting up authentication, the SDK will always try to use the key flow first and search for credentials in several locations, following a specific order:

  1. Explicit configuration, e.g. by using the optionConfiguration(service_account_key_path="path/to/sa_key.json")

  2. Environment variable, e.g. by settingSTACKIT_SERVICE_ACCOUNT_KEY_PATH

  3. Credentials file

    The SDK will check the credentials file located in the path defined by theSTACKIT_CREDENTIALS_PATH env var, if specified,or in$HOME/.stackit/credentials.json as a fallback.The credentials file should be a json and each credential should be set using the name of the respective environment variable, as stated below in each flow. Example:

    {"STACKIT_SERVICE_ACCOUNT_TOKEN":"foo_token","STACKIT_SERVICE_ACCOUNT_KEY_PATH":"path/to/sa_key.json"}

Check thecustom authentication example for more details.

Key flow

The following instructions assume that you have created a service account and assigned it the necessary permissions, e.g.project.owner.

To use the key flow, you need to have a service account key, which must have an RSA key-pair attached to it.

When creating the service account key, a new pair can be created automatically, which will be included in the service account key.This will make it much easier to configure the key flow authentication in the SDK, by just providing the service account key.

Optionally, you can provide your own private key when creating the service account key, which will then require you to also provide it explicitly to the SDK, additionally to the service account key.Check the STACKIT Knowledge Base for anexample of how to create your own key-pair.

To configure the key flow, follow this steps:

  1. Create a service account key:

    • Use the STACKIT Portal: go to theService Accounts tab, choose aService Account and go toService Account Keys to create a key. For more details, seeCreate a service account key.
  2. Save the content of the service account key by copying it and saving it in a JSON file. The expected format of the service account key isJSON with the following structure:

    {"id":"uuid","publicKey":"public key","createdAt":"2023-08-24T14:15:22Z","validUntil":"2023-08-24T14:15:22Z","keyType":"USER_MANAGED","keyOrigin":"USER_PROVIDED","keyAlgorithm":"RSA_2048","active":true,"credentials": {"kid":"string","iss":"my-sa@sa.stackit.cloud","sub":"uuid","aud":"string","privateKey":"(OPTIONAL) private key when generated by the SA service"  }}
  3. Configure the service account key for authentication in the SDK by following one of the alternatives below:

    • using the configuration options:
      config=Configuration(   ...service_account_key_path="/path/to/service_account_key.json"   ...)
    • setting the environment variable:STACKIT_SERVICE_ACCOUNT_KEY_PATH
    • settingSTACKIT_SERVICE_ACCOUNT_KEY_PATH in the credentials file (see above)

Optionally, only if you have provided your own RSA key-pair when creating the service account key, you also need to configure your private key (takes precedence over the one included in the service account key, if present).The private key must be PEM encoded and can be provided using one of the options below:

  • using the configuration options:
    config=Configuration(    ...private_key_path="/path/to/private_key.json"    ...)
  • setting the environment variable:STACKIT_PRIVATE_KEY_PATH
  • settingSTACKIT_PRIVATE_KEY_PATH in the credentials file (see above)
  1. The SDK will search for the keys and, if valid, will use them to get access and refresh tokens which will be used to authenticate all the requests.

Token flow

Using this flow is less secure since the token is long-lived. You can provide the token in several ways:

  1. Using the configuration option:
    config=Configuration(   ...service_account_token="your token"   ...)
  2. Setting the environment variableSTACKIT_SERVICE_ACCOUNT_TOKEN
  3. Setting it in the credentials file (see above)

Using custom endpoints

The example below shows how to use the STACKIT Python SDK in custom STACKIT environments.

fromstackit.iaas.api.default_apiimportDefaultApifromstackit.core.configurationimportConfigurationproject_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"# Create a new API client that uses custom authentication and service endpointsconfig=Configuration(service_account_key_path="/home/bob/.stackit/sa_key.json",custom_token_endpoint="https://service-account.api.stackit.cloud/token",custom_endpoint="https://iaas.api.eu01.stackit.cloud",)client=DefaultApi(config)print(client.list_project_nics(project_id=project_id,))

Reporting issues

If you encounter any issues or have suggestions for improvements, please open an issue in the repository or create a ticket in theSTACKIT Help Center.

Contribute

Installing in editable mode

For developing it is recommended to installpoetry. An installation guide can be foundhere.

For development it is best to install the packages in editable mode.You can install a single package in editable mode using the following command:

pip install -e services/<service-name>

Where<service-name> has to be replaced by the name of the service you want to install.Forredis the command would be:

pip install -e services/redis

There are optional dev-dependencies that requirepoetry. Those can be installed with:

poetry install -C<path-to-the-service> --only dev --no-root

If you want to install all services in editable mode, as well as the dev-dependencies, you can use theMakefile with the following command:

make install-dev

When using themake install-dev command it is important to preventpoetry from creating a different environment for every package.This can be achieved by runningpoetry config virtualenvs.create false, but there are multiple way to achieve this. You can check thepoetry docs to see which option fits best for you.

Release creation

See therelease documentation for further information.

License

Apache 2.0

About

The STACKIT SDK for Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors9

Languages


[8]ページ先頭

©2009-2025 Movatter.jp