Naver Cloud Platform Python SDK

2.8.1 (ncloud meta-package) · active · verified Sun Mar 01

Official Python SDK for Naver Cloud Platform (NCP) — South Korea's primary cloud provider, equivalent to AWS in the Korean market. Provides programmatic access to NCP infrastructure services: servers, VPC, CDN, DNS, Object Storage, and more. The SDK is split into service-specific packages (ncloud-server, ncloud-vserver, ncloud-vpc, ncloud-cdn, etc.) — install only the services you need. IMPORTANT: NCP has two distinct environments — Classic and VPC — with separate SDK modules, different API endpoints, and incompatible APIs. ncloud-server targets Classic, ncloud-vserver targets VPC. New accounts should use VPC.

Warnings

Install

Imports

Quickstart

Always use ncloud-vserver (VPC) for new projects. ncloud-server (Classic) is legacy. Product codes for server images and instance types must be retrieved via API (getServerImageProductList, getServerProductList) — they are not human-readable strings and differ between Classic and VPC environments.

# Step 1: Set up credentials
# Option A: Config file at ~/.ncloud/configure
# [DEFAULT]
# ncloud_access_key_id = YOUR_ACCESS_KEY
# ncloud_secret_access_key = YOUR_SECRET_KEY

# Option B: Environment variables
# export NCLOUD_ACCESS_KEY_ID=YOUR_ACCESS_KEY
# export NCLOUD_SECRET_KEY=YOUR_SECRET_KEY

# Step 2: VPC Server operations (recommended for new accounts)
import ncloud_vserver
from ncloud_vserver.api.v2_api import V2Api
from ncloud_vserver.rest import ApiException
import ncloud_apikey

# Load credentials from config file or env vars
apikeys = ncloud_apikey.ncloud_key.NcloudKey().keys()

configuration = ncloud_vserver.Configuration()
configuration.access_key = apikeys['access_key']
configuration.secret_key = apikeys['secret_key']

api = V2Api(ncloud_vserver.ApiClient(configuration))

# List server instances
try:
    response = api.get_server_instance_list(
        ncloud_vserver.GetServerInstanceListRequest()
    )
    for server in response.get_server_instance_list_response.server_instance_list:
        print(server.server_name, server.server_instance_status.code_name)
except ApiException as e:
    print(f'API error: {e}')

# Create a server instance (VPC)
try:
    request = ncloud_vserver.CreateServerInstancesRequest(
        vpc_no='YOUR_VPC_NO',
        subnet_no='YOUR_SUBNET_NO',
        server_image_product_code='SW.VSVR.OS.LNX64.CNTOS.0703.B050',  # CentOS 7
        server_product_code='SVR.VSVR.STAND.C002.M008.NET.SSD050.B050.G002',
    )
    response = api.create_server_instances(request)
    print(response)
except ApiException as e:
    print(f'Create error: {e}')

# Classic environment (legacy — use only if on Classic account)
import ncloud_server
from ncloud_server.api.v2_api import V2Api as ClassicV2Api

classic_config = ncloud_server.Configuration()
classic_config.access_key = apikeys['access_key']
classic_config.secret_key = apikeys['secret_key']

classic_api = ClassicV2Api(ncloud_server.ApiClient(classic_config))
try:
    response = classic_api.get_server_instance_list(
        ncloud_server.GetServerInstanceListRequest()
    )
except ApiException as e:
    print(f'Classic API error: {e}')

# CDN (works for both Classic and VPC)
import ncloud_cdn
from ncloud_cdn.api.v2_api import V2Api as CdnV2Api

cdn_config = ncloud_cdn.Configuration()
cdn_config.access_key = apikeys['access_key']
cdn_config.secret_key = apikeys['secret_key']

cdn_api = CdnV2Api(ncloud_cdn.ApiClient(cdn_config))
try:
    response = cdn_api.get_cdn_plus_instance_list(
        ncloud_cdn.GetCdnPlusInstanceListRequest()
    )
    print(response)
except ApiException as e:
    print(f'CDN error: {e}')

view raw JSON →