Give AlbumentationsX a star on GitHub — it powers this leaderboard

Star on GitHub

yandexcloud

The Yandex Cloud official SDK

Downloads: 0 (30 days)

Description

PyPI Version Build Status License

<!-- Badges -->

Yandex.Cloud SDK (Python)

Need to automate your infrastructure or use services provided by Yandex.Cloud? We've got you covered.

Installation:

pip install yandexcloud

Getting started

There are several options for authorization your requests - OAuth Token, Metadata Service (if you're executing your code inside VMs or Cloud Functions running in Yandex.Cloud), Service Account Keys, and externally created IAM tokens.

OAuth Token

sdk = yandexcloud.SDK(token='AQAD-.....')

Metadata Service

Don't forget to assign Service Account for your Instance or Function and grant required roles.

sdk = yandexcloud.SDK()

Service Account Keys

# you can store and read it from JSON file
sa_key = {
    "id": "...",
    "service_account_id": "...",
    "private_key": "..."
}

sdk = yandexcloud.SDK(service_account_key=sa_key)

IAM tokens

sdk = yandexcloud.SDK(iam_token="t1.9eu...")

Check examples directory for more examples.

Override service endpoint

Supported services

Service NameAlias
yandex.cloud.ai.foundation_modelsai-foundation-models
yandex.cloud.ai.llmai-llm
yandex.cloud.ai.ocrai-vision-ocr
yandex.cloud.ai.sttai-stt
yandex.cloud.ai.translateai-translate
yandex.cloud.ai.ttsai-speechkit
yandex.cloud.ai.visionai-vision
yandex.cloud.apploadbalanceralb
yandex.cloud.billingbilling
yandex.cloud.cdncdn
yandex.cloud.certificatemanager.v1.certificate_content_servicecertificate-manager-data
yandex.cloud.certificatemanagercertificate-manager
yandex.cloud.computecompute
yandex.cloud.containerregistrycontainer-registry
yandex.cloud.dataproc.managerdataproc-manager
yandex.cloud.dataprocdataproc
yandex.cloud.dataspheredatasphere
yandex.cloud.datatransferdatatransfer
yandex.cloud.dnsdns
yandex.cloud.endpointendpoint
yandex.cloud.iamiam
yandex.cloud.iot.devicesiot-devices
yandex.cloud.k8smanaged-kubernetes
yandex.cloud.kms.v1.symmetric_crypto_servicekms-crypto
yandex.cloud.kmskms
yandex.cloud.loadbalancerload-balancer
yandex.cloud.loadtestingloadtesting
yandex.cloud.lockbox.v1.payload_servicelockbox-payload
yandex.cloud.lockboxlockbox
yandex.cloud.logging.v1.log_ingestion_servicelog-ingestion
yandex.cloud.logging.v1.log_reading_servicelog-reading
yandex.cloud.logginglogging
yandex.cloud.marketplacemarketplace
yandex.cloud.mdb.clickhousemanaged-clickhouse
yandex.cloud.mdb.elasticsearchmanaged-elasticsearch
yandex.cloud.mdb.greenplummanaged-greenplum
yandex.cloud.mdb.kafkamanaged-kafka
yandex.cloud.mdb.mongodbmanaged-mongodb
yandex.cloud.mdb.mysqlmanaged-mysql
yandex.cloud.mdb.opensearchmanaged-opensearch
yandex.cloud.mdb.postgresqlmanaged-postgresql
yandex.cloud.mdb.redismanaged-redis
yandex.cloud.mdb.sqlservermanaged-sqlserver
yandex.cloud.operationoperation
yandex.cloud.organizationmanagerorganization-manager
yandex.cloud.resourcemanagerresource-manager
yandex.cloud.serverless.apigateway.websocketapigateway-connections
yandex.cloud.serverless.apigatewayserverless-apigateway
yandex.cloud.serverless.containersserverless-containers
yandex.cloud.serverless.functionsserverless-functions
yandex.cloud.serverless.triggersserverless-triggers
yandex.cloud.sparkmanaged-spark
yandex.cloud.storagestorage-api
yandex.cloud.trinotrino
yandex.cloud.vpcvpc
yandex.cloud.ydbydb

Override in client

from yandex.cloud.vpc.v1.network_service_pb2_grpc import NetworkServiceStub
from yandexcloud import SDK

sdk = SDK(iam_token="t1.9eu...")
new_network_client_endpoint = "example.new.vpc.very.new.yandex:50051"
insecure = False # by default is False, but if server does not support verification can be set to True
network_client = sdk.client(NetworkServiceStub, endpoint=new_network_client_endpoint, insecure=False)

Override in sdk config

To override endpoints provide dict in format {alias : new-endpoint}

from yandex.cloud.vpc.v1.network_service_pb2_grpc import NetworkServiceStub
from yandexcloud import SDK
new_network_client_endpoint = "example.new.vpc.very.new.yandex:50051"
sdk = SDK(iam_token="t1.9eu...", endpoints={"vpc": new_network_client_endpoint})
insecure = False # by default is False, but if server does not support verification can be set to True
network_client = sdk.client(NetworkServiceStub, insecure=False)

Notice: if both overrides are used for same endpoint, override by client has priority

Switch SDK region

from yandexcloud import SDK, set_up_yc_api_endpoint
kz_region_endpoint = "api.yandexcloud.kz"
# this will make SDK list endpoints from KZ yc installation
sdk = SDK(iam_token="t1.9eu...", endpoint="api.yandexcloud.kz")
# or you can use global function
set_up_yc_api_endpoint(kz_region_endpoint)

Retries

SDK provide built-in retry policy, that supports exponential backoff and jitter, and also retry budget. It's necessary to avoid retry amplification.

import grpc
from yandexcloud import SDK, RetryPolicy

sdk = SDK(retry_policy=RetryPolicy())

SDK provide different modes for retry throttling policy:

  • persistent is suitable when you use SDK in any long-lived application, when SDK instance will live long enough for manage budget;
  • temporary is suitable when you use SDK in any short-lived application, e.g. scripts or CI/CD.

By default, SDK will use temporary mode, but you can change it through throttling_mode argument.

Contributing

Dependencies

We use uv to manage dependencies and run commands in Makefile. Install it with official standalone inst