Skip to main content

[Unofficial] Yandex.Cloud REST API Client

License: GPL v3 PyPI - Python Version PyPi Package

ALPHA VERSION

Warning: Some features may be unavailable or unstable. The client is developed by one developer in his spare time. If you are not satisfied with this, you can always add or change the client by creating a pull request.

Probably, this REST API Client will make your life with Yandex.Cloud a little easier.

Installing

  • Installing with pip:
pip3 install yandex-cloud-client
  • Also, you can install from source with:
git clone https://github.com/akimrx/python-yc-client  --recursive
cd python-yc-client 
make install

or

git clone https://github.com/akimrx/python-yc-client  --recursive
cd python-yc-client 
python3 setup.py install

Getting started

Client and authorization

The first step is to import required client of the Yandex.Cloud Services.
Each client of a Yandex.Cloud service inherits authorization from the base client, which supports three methods:

from yandex_cloud_client import ComputeClient

client = ComputeClient(oauth_token='YOUR_OAUTH_TOKEN')
from yandex_cloud_client import ComputeClient

client = ComputeClient(iam_token='YOUR_IAM_TOKEN')
import json
from yandex_cloud_client import ComputeClient

with open('/path/to/key.json', 'r') as infile:
    credentials = json.load(infile)

client = ComputeClient(service_account_key=credentials)

You can get key.json from Yandex Cloud CLI:

yc iam key create --service-account-name my-robot -o my-robot-key.json

Basic example for Instance from Compute Cloud Service

from yandex_cloud_client import ComputeClient

compute = ComputeClient(oauth_token='YOUR_OAUTH_TOKEN')


def show_instance_and_restart(instance_id):
    instance = compute.instance(instance_id, metadata=True)
    print('Name:', instance.name)
    print('Cores:', instance.resources.cores)
    print('Memory:', instance.resources.memory)
    print('SSH-keys:', instance.metadata.ssh_keys)

    if instance.running:
        operation = instance.restart()
        if operation.completed:
            print(f'Instance {instance.name} restarted!')

    print('Current instance state:', instance.status)


def boot_disk_snapshot(instance_id):
    instance = compute.instance(instance_id)

    if not instance.stopped:  # also, you can use instance.status != 'STOPPED'
        print('Stopping instance..')
        instance.stop()

    print('Creating snapshot for boot disk..')
    instance.boot_disk.create_snapshot()
    print('Starting instance without awaiting complete.')
    instance.start(await_complete=False)



if __name__ == '__main__':
    show_instance_and_restart('YOUR_INSTANCE_ID')
    boot_disk_snapshot('YOUR_INSTANCE_ID')

See more examples here

Logging

This library uses the logging module.

Example of usage:

import logging

logging.basicConfig(level=logging.INFO,
                    format='[%(levelname)s] %(message)s')
logger = logging.getLogger(__name__)

Borrowed arch design

The client was written under the inspiration of architecture design:

Metadata

Release files for yandex-cloud-client 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yandex-cloud-client 1.0.5
File Size Uploaded
yandex-cloud-client-1.0.5.tar.gz 25.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yandex-cloud-client 1.0.5
File Interpreter ABI Platform
yandex_cloud_client-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 73.6 kB

Release files / yandex-cloud-client-1.0.5.tar.gz

Download URL yandex-cloud-client-1.0.5.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a4281b1cb9d78a148540a2d99b9e197218cf9e66a07a134819f256277cb773b5
BLAKE2b-256 checksum
How to use checksums
eb436b7c51eb56ace54068d719e581e9fec7f0c80c9efef3277331ba784e16e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.6.9

Release files / yandex_cloud_client-1.0.5-py3-none-any.whl

Download URL yandex_cloud_client-1.0.5-py3-none-any.whl
Size 48.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5edec2b6c9871da166bbbde1958eacc5fdcad80b20408bf192b9e0914e6c0710
BLAKE2b-256 checksum
How to use checksums
0dc1b0d48b8f4e0b62578223404a420c1fbfc67c9b1456de99d37339a3eb8bcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 release files

1.0.4

3 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page