To authenticate in Yandex Cloud ML SDK, you need to provide the YCloudML object to the model. This object contains the following fields:
folder_id- ID of the folder you are going to use to work with models.
auth- Key, token, or other authentication data to identify the user. You can specify the
authfield value explicitly or get it automatically from the environment.
If set explicitly, the auth field value can be one of the following:
String Authentication
As a string, you can provide:
- IAM token of a user or service account.
- Secret part of the service account API key.
- OAuth token of a user account.
The SDK will automatically determine the type of authentication data.
Authentication Classes
Object of one of the following classes:
:py:class:`yandex_cloud_ml_sdk.auth.APIKeyAuth` - Allows you to explicitly set authentication by the provided API key.
Example:
auth = APIKeyAuth('<API_key>')
:py:class:`yandex_cloud_ml_sdk.auth.IAMTokenAuth` - Allows you to explicitly set authentication by the provided IAM token.
Example:
auth = IAMTokenAuth('<IAM_token>')
:py:class:`yandex_cloud_ml_sdk.auth.OAuthTokenAuth` - Allows you to explicitly set authentication by the provided OAuth token.
Example:
auth = OAuthTokenAuth('<OAuth_token>')
:py:class:`yandex_cloud_ml_sdk.auth.MetadataAuth` - Allows you to explicitly set authentication as the service account specified in the Yandex Compute Cloud VM metadata.
Example:
auth = MetadataAuth()
:py:class:`yandex_cloud_ml_sdk.auth.EnvIAMTokenAuth` - Allows you to explicitly set authentication using the IAM token specified in the
YC_TOKENor any other environment variable.Examples:
auth = EnvIAMTokenAuth() # or auth = EnvIAMTokenAuth("ENV_VAR")
The SDK obtains the IAM token from this environment variable with each request, so you can occasionally update the IAM token in the environment variable yourself outside the SDK. This authentication option is optimal for use with a service agent in Yandex DataSphere if that service has access to other resources in the user's cloud.
:py:class:`yandex_cloud_ml_sdk.auth.YandexCloudCLIAuth` - Allows you to explicitly set authentication as a user_1 or service account specified_1 in the Yandex Cloud CLI_1 profile on the user's computer.
Example:
auth = YandexCloudCLIAuth()
:py:class:`yandex_cloud_ml_sdk.auth.NoAuth` - Specifies that no authentication data will be provided.
Example:
auth = NoAuth()
You can get these classes by importing them from the ML SDK library. Here is an example:
from yandex_cloud_ml_sdk.auth import APIKeyAuthIf the auth field is not explicitly set, the SDK will automatically try to select one of the authentication options in the following order:
Authenticate using the API key from the
YC_API_KEYenvironment variable if it is set.Authenticate using the IAM token from the
YC_IAM_TOKENenvironment variable if it is set.Authenticate using the OAuth token from the
YC_OAUTH_TOKENenvironment variable if it is set.If none of these environment variables are set, the SDK will attempt to authenticate using the IAM token of the service account specified in the VM metadata.
Authenticate using the IAM token from the
YC_TOKENenvironment variable if it is set.The SDK obtains the IAM token from this environment variable with each request, so you can occasionally update the IAM token in the
YC_TOKENenvironment variable yourself outside the SDK.If the previous options fail, the SDK will attempt to authenticate using the IAM token of the user_2 or service account specified_2 in the Yandex Cloud CLI_2 profile on the user's computer.
Note
The maximum lifetime of an IAM token is 12 hours. Keep this in mind when sending requests with authentication based on an IAM token specified in a string, object of the IAMTokenAuth class, or the YC_IAM_TOKEN environment variable.
.. automodule:: yandex_cloud_ml_sdk.auth :no-undoc-members: