Oven logo

Oven

Published

The Yandex.Cloud official SDK

PyPI Version Build Status License

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.storagestorage-api
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)

Contributing

Dependencies

Use make deps command to install library, its production and development dependencies.

Formatting

Use make format to autoformat code with black tool.

Tests

  • make test to run tests for current python version
  • make lint to run only linters for current python version
  • make tox-current to run all checks (tests + code style checks + linters + format check) for current python version
  • make tox to run all checks for all supported (installed in your system) python versions
  • make test-all-versions to run all checks for all supported python versions in docker container

Maintaining

If pull request consists of several meaningful commits, that should be preserved, then use "Rebase and merge" option. Otherwise use "Squash and merge".

New release (changelog, tag and pypi upload) will be automatically created on each push to master via Github Actions workflow.