### Install Scaleway SDK (Synchronous) Source: https://github.com/scaleway/scaleway-sdk-python/blob/main/docs/index.md Install the synchronous version of the Scaleway Python SDK from PyPI. This is the default installation for most use cases. ```default pip install scaleway ``` -------------------------------- ### Initialize Scaleway Client (From Config) Source: https://github.com/scaleway/scaleway-sdk-python/blob/main/docs/index.md Initialize the Scaleway client using configuration from a file and environment variables. This simplifies setup by avoiding hardcoded credentials. ```default from scaleway import Client client = Client.from_config_file_and_env() ``` -------------------------------- ### Initialize Scaleway Client (Minimal Setup) Source: https://github.com/scaleway/scaleway-sdk-python/blob/main/docs/index.md Initialize the Scaleway client with explicit credentials and project details. Ensure you have your API keys and project ID ready. ```default from scaleway import Client from scaleway.registry.v1 import RegistryV1API client = Client( access_key="SCWXXXXXXXXXXXXXXXXX", secret_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", default_project_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", default_region="fr-par", default_zone="fr-par-1", ) registry_api = RegistryV1API(client) ``` -------------------------------- ### Install Scaleway Python SDK Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Install the synchronous or asynchronous flavors of the Scaleway Python SDK using pip. ```bash # Synchronous pip install scaleway # Asynchronous (asyncio) pip install scaleway-async ``` -------------------------------- ### Install Scaleway SDK (Asynchronous) Source: https://github.com/scaleway/scaleway-sdk-python/blob/main/docs/index.md Install the asynchronous version of the Scaleway Python SDK from PyPI. Use this if your application requires non-blocking I/O operations. ```default pip install scaleway-async ``` -------------------------------- ### Manage Container Registry Namespaces and Images Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Use `RegistryV1API` to manage container registry namespaces, images, and tags. Supports listing, fetching all, getting specific namespaces, creating new ones, listing images, waiting for namespaces to be ready, and updating image visibility. ```python from scaleway import Client from scaleway.registry.v1 import RegistryV1API from scaleway.registry.v1.types import ImageVisibility client = Client.from_config_file_and_env() api = RegistryV1API(client) # List namespaces (single page) result = api.list_namespaces(region="fr-par") for ns in result.namespaces: print(ns.id, ns.name, ns.endpoint) # Fetch ALL namespaces (auto-pagination) all_namespaces = api.list_namespaces_all(project_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") # Get a specific namespace ns = api.get_namespace(namespace_id="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") # Create a namespace new_ns = api.create_namespace( name="my-registry", description="Production images", is_public=False, ) print("Namespace endpoint:", new_ns.endpoint) # List all images in a namespace images = api.list_images_all(namespace_id=new_ns.id) for image in images: print(image.name, image.status) # Wait until a namespace is fully ready (polls until non-transient status) ready_ns = api.wait_for_namespace(namespace_id=new_ns.id) print("Ready:", ready_ns.status) # Update image visibility api.update_image( image_id="bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", visibility=ImageVisibility.public, ) ``` -------------------------------- ### Manage Kubernetes Clusters with K8SV1API Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Utilize `K8SV1API` for managing Kubernetes clusters (Kapsule and Kosmos), node pools, and upgrades. This includes listing, creating, waiting for readiness, installing kubeconfig, upgrading, and deleting clusters. ```python from scaleway import Client from scaleway.k8s.v1 import K8SV1API from scaleway.k8s.v1.types import ( CNI, CreateClusterRequestPoolConfig, PoolVolumeType, Runtime, WaitForOptions, ) client = Client.from_config_file_and_env() api = K8SV1API(client) # List all clusters clusters = api.list_clusters_all(region="fr-par") for cluster in clusters: print(cluster.id, cluster.name, cluster.status) # Create a Kapsule cluster with one initial node pool pool_config = CreateClusterRequestPoolConfig( name="default-pool", node_type="DEV1-M", size=3, autoscaling=True, min_size=1, max_size=5, container_runtime=Runtime.containerd, root_volume_type=PoolVolumeType.sbs_15k, root_volume_size=20000000000, # 20 GB in bytes ) cluster = api.create_cluster( type_="kapsule", name="my-production-cluster", description="Production Kubernetes cluster", version="1.30", cni=CNI.cilium, region="fr-par", pools=[pool_config], tags=["production"], ) print("Cluster ID:", cluster.id) # Block until cluster is ready (default timeout: 5 minutes) ready_cluster = api.wait_for_cluster( cluster_id=cluster.id, options=WaitForOptions(timeout=600, min_delay=5, max_delay=60), ) print("Cluster status:", ready_cluster.status) # Get the kubeconfig file kubeconfig = api.install_cluster_kubeconfig(cluster_id=cluster.id) # Upgrade a cluster to a new Kubernetes version api.upgrade_cluster(cluster_id=cluster.id, version="1.31") # Delete a cluster api.delete_cluster(cluster_id=cluster.id, with_block_volumes=False) ``` -------------------------------- ### Bridge Types Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Introduces `ScwFile`, `Region`, and `Zone` as bridge types for handling geography and binary file responses, with examples for their usage in API calls. ```APIDOC ## `ScwFile`, `Region`, `Zone` — Bridge Types `scaleway_core.bridge` exposes typed geography helpers (`Region`, `Zone`, `ALL_REGIONS`, `ALL_ZONES`) and `ScwFile` (for binary file responses such as kubeconfig downloads). ```python from scaleway_core.bridge import Region, Zone, ALL_REGIONS, ALL_ZONES, ScwFile # ALL_REGIONS and ALL_ZONES list all Scaleway regions/zones print(ALL_REGIONS) # e.g. ["fr-par", "nl-ams", "pl-waw", ...] print(ALL_ZONES) # e.g. ["fr-par-1", "fr-par-2", "nl-ams-1", ...] # Use in API calls from scaleway import Client from scaleway.k8s.v1 import K8SV1API client = Client.from_config_file_and_env() api = K8SV1API(client) # ScwFile is returned by download methods (binary content with name + content_type) kubeconfig: ScwFile = api.install_cluster_kubeconfig( cluster_id="ffffffff-ffff-ffff-ffff-ffffffffffff", region=Region("fr-par"), ) print("Filename:", kubeconfig.name) print("Content type:", kubeconfig.content_type) with open(f"/tmp/{kubeconfig.name}", "wb") as f: f.write(kubeconfig.content) ``` ``` -------------------------------- ### Client Initialization Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Demonstrates how to initialize the Scaleway Client, either explicitly with credentials or by loading from configuration files and environment variables. It also shows how to validate credentials and instantiate an API client. ```APIDOC ## Client Initialization `Client` (from `scaleway_core`) is the entry point for all SDK operations. It holds credentials and default region/zone/project settings; every API class requires a configured `Client`. ```python from scaleway import Client from scaleway.registry.v1 import RegistryV1API # --- Option 1: Explicit configuration --- client = Client( access_key="SCWXXXXXXXXXXXXXXXXX", # format: SCWXXXXXXXXXXXXXXXXX secret_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", default_project_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", default_organization_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", default_region="fr-par", default_zone="fr-par-1", ) # --- Option 2: Load from ~/.config/scw/config.yaml and environment variables --- # Environment variables (take precedence over config file): # SCW_ACCESS_KEY, SCW_SECRET_KEY, SCW_DEFAULT_REGION, SCW_DEFAULT_ZONE, # SCW_DEFAULT_PROJECT_ID, SCW_DEFAULT_ORGANIZATION_ID, SCW_CONFIG_PATH, SCW_PROFILE client = Client.from_config_file_and_env() # Validate credentials before making any API calls (raises ValueError on invalid format) client.validate() registry_api = RegistryV1API(client) print(registry_api.list_namespaces()) ``` ## Client — `from_config_file` / `from_env` Load a `Client` exclusively from the Scaleway YAML config file or from environment variables for fine-grained control. ```python from scaleway_core.profile import Profile from scaleway_core.client import Client # Load a named profile from a specific config file profile = Profile.from_config_file( filepath="/etc/scaleway/config.yaml", profile_name="production", # reads config["profiles"]["production"] ) client = Client.from_profile(profile) # Load only from environment variables env_profile = Profile.from_env() client = Client.from_profile(env_profile) # Config file YAML structure (example): # access_key: SCWXXXXXXXXXXXXXXXXX # secret_key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # default_region: fr-par # default_zone: fr-par-1 # profiles: # production: # default_project_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` ``` -------------------------------- ### Create and list API keys with IAM API Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Shows how to create an API key for an IAM application and list all existing API keys. Requires application ID and default project ID for creation. ```python api_key = api.create_api_key( application_id="cccccccc-cccc-cccc-cccc-cccccccccccc", description="CI/CD pipeline key", default_project_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", ) print("Access Key:", api_key.access_key) print("Secret Key:", api_key.secret_key) ``` ```python keys = api.list_api_keys_all() ``` -------------------------------- ### Low-level pagination with fetch_all_pages Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Demonstrates using the `fetch_all_pages` utility for custom pagination logic, specifically for listing registry namespaces. Allows fine-grained control over fetching. ```python from scaleway.registry.v1 import RegistryV1API from scaleway.registry.v1.types import ListNamespacesResponse # ... client initialization ... registry = RegistryV1API(client) all_namespaces = fetch_all_pages( type=ListNamespacesResponse, key="namespaces", fetcher=registry.list_namespaces, args={"region": "fr-par", "page_size": 10}, ) ``` -------------------------------- ### Auto-paginate Instances and RDB backups Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Fetches all instances and database backups, automatically handling pagination. Useful for retrieving complete lists of resources. ```python from scaleway import Client from scaleway.instance.v1 import InstanceV1API from scaleway.rdb.v1 import RdbV1API from scaleway_core.utils import fetch_all_pages client = Client.from_config_file_and_env() # Auto-paginate Instances api = InstanceV1API(client) all_servers = api.list_servers_all( commercial_type="GP1-S", tags=["env:prod"], ) print(f"Total servers: {len(all_servers)}") # Auto-paginate database backups filtered by instance rdb = RdbV1API(client) all_backups = rdb.list_database_backups_all( instance_id="dddddddd-dddd-dddd-dddd-dddddddddddd", page_size=50, # controls page size per request ) print(f"Total backups: {len(all_backups)}") ``` -------------------------------- ### Waiter Helpers Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Demonstrates how to use the SDK's built-in and custom waiter functions to poll for resource readiness, with configurable options for timeouts and delays. ```APIDOC ## Waiter Helpers — `wait_for_resource` / `WaitForOptions` The SDK includes synchronous and asynchronous resource pollers with configurable exponential backoff. APIs that support long-running operations expose a `wait_for_*()` method. ```python from scaleway import Client from scaleway.rdb.v1 import RdbV1API from scaleway_core.utils.waiter import WaitForOptions, wait_for_resource from scaleway.rdb.v1.content import INSTANCE_TRANSIENT_STATUSES client = Client.from_config_file_and_env() api = RdbV1API(client) # Use the built-in wait_for_instance helper ready = api.wait_for_instance( instance_id="eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee", options=WaitForOptions( timeout=600, # max seconds to wait (default: 300) min_delay=5, # start polling every 5 seconds max_delay=60, # cap delay at 60 seconds (exponential backoff) ), ) print("Final state:", ready.status) # Custom waiter using low-level wait_for_resource instance = wait_for_resource( fetcher=api.get_instance, options=WaitForOptions( timeout=300, stop=lambda res: res.status not in INSTANCE_TRANSIENT_STATUSES, ), args={"instance_id": "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee"}, ) ``` ``` -------------------------------- ### Initialize Scaleway Client Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Initialize the Scaleway Client with explicit credentials and settings, or load from configuration files and environment variables. The client is required for all API operations. Validate credentials before use. ```python from scaleway import Client from scaleway.registry.v1 import RegistryV1API # --- Option 1: Explicit configuration --- client = Client( access_key="SCWXXXXXXXXXXXXXXXXX", # format: SCWXXXXXXXXXXXXXXXXX secret_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", default_project_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", default_organization_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", default_region="fr-par", default_zone="fr-par-1", ) # --- Option 2: Load from ~/.config/scw/config.yaml and environment variables --- # Environment variables (take precedence over config file): # SCW_ACCESS_KEY, SCW_SECRET_KEY, SCW_DEFAULT_REGION, SCW_DEFAULT_ZONE, # SCW_DEFAULT_PROJECT_ID, SCW_DEFAULT_ORGANIZATION_ID, SCW_CONFIG_PATH, SCW_PROFILE client = Client.from_config_file_and_env() # Validate credentials before making any API calls (raises ValueError on invalid format) client.validate() registry_api = RegistryV1API(client) print(registry_api.list_namespaces()) ``` -------------------------------- ### Manage Scaleway Instances Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Use InstanceV1API to manage virtual machine Instances, including listing, fetching, creating, performing lifecycle actions (poweron, reboot, etc.), and deleting. Zone-level resources require specifying the zone. ```python from scaleway import Client from scaleway.instance.v1 import InstanceV1API from scaleway.instance.v1.types import ServerAction client = Client.from_config_file_and_env() api = InstanceV1API(client) # List all Instances in the default zone (single page) response = api.list_servers() for server in response.servers: print(server.id, server.name, server.state) # Fetch ALL pages at once (auto-pagination) all_servers = api.list_servers_all( commercial_type="GP1-S", tags=["prod", "web"], ) # Get a specific Instance server = api.get_server(server_id="11111111-1111-1111-1111-111111111111") print(server.server.public_ip) # Create a new Instance new_server = api._create_server( commercial_type="DEV1-S", image="ubuntu_jammy", name="my-web-server", protected=False, tags=["dev"], ) print("Created:", new_server.server.id) # Perform a lifecycle action: poweron / poweroff / reboot / backup / terminate api.server_action( server_id="11111111-1111-1111-1111-111111111111", action=ServerAction.reboot, ) # Delete an Instance api.delete_server(server_id="11111111-1111-1111-1111-111111111111") ``` -------------------------------- ### Pagination Helpers - Auto-paginate Instances Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Automatically fetch all pages of server instances, useful for retrieving large datasets. ```APIDOC from scaleway import Client from scaleway.instance.v1 import InstanceV1API client = Client.from_config_file_and_env() # Auto-paginate Instances api = InstanceV1API(client) all_servers = api.list_servers_all( commercial_type="GP1-S", tags=["env:prod"], ) print(f"Total servers: {len(all_servers)}") ``` -------------------------------- ### Pagination Helpers - Low-level fetch_all_pages Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Use the low-level `fetch_all_pages` utility for custom pagination logic, such as with the Registry API. ```APIDOC from scaleway_core.utils import fetch_all_pages from scaleway.registry.v1 import RegistryV1API from scaleway.registry.v1.types import ListNamespacesResponse client = Client.from_config_file_and_env() registry = RegistryV1API(client) all_namespaces = fetch_all_pages( type=ListNamespacesResponse, key="namespaces", fetcher=registry.list_namespaces, args={"region": "fr-par", "page_size": 10}, ) ``` -------------------------------- ### Create and manage SSH keys with IAM API Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Demonstrates creating, listing, and deleting SSH keys using the IAM API. Ensure the public key is correctly formatted. ```python ssh_key = api.create_ssh_key( public_key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... user@host", name="my-laptop-key", ) print("SSH Key ID:", ssh_key.id) ``` ```python all_keys = api.list_ssh_keys_all( order_by=ListSSHKeysRequestOrderBy.name_asc, disabled=False, ) ``` ```python api.delete_ssh_key(ssh_key_id=ssh_key.id) ``` -------------------------------- ### Load Scaleway Client from Profile Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Load a Scaleway Client exclusively from a named profile in a specific config file or solely from environment variables. This provides more granular control over client configuration. ```python from scaleway_core.profile import Profile from scaleway_core.client import Client # Load a named profile from a specific config file profile = Profile.from_config_file( filepath="/etc/scaleway/config.yaml", profile_name="production", # reads config["profiles"]["production"] ) client = Client.from_profile(profile) # Load only from environment variables env_profile = Profile.from_env() client = Client.from_profile(env_profile) # Config file YAML structure (example): # access_key: SCWXXXXXXXXXXXXXXXXX # secret_key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # default_region: fr-par # default_zone: fr-par-1 # profiles: # production: # default_project_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` -------------------------------- ### Pagination Helpers - Auto-paginate Database Backups Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Fetch all database backups for a given instance, with options to control page size. ```APIDOC from scaleway.rdb.v1 import RdbV1API client = Client.from_config_file_and_env() rdb = RdbV1API(client) all_backups = rdb.list_database_backups_all( instance_id="dddddddd-dddd-dddd-dddd-dddddddddddd", page_size=50, # controls page size per request ) print(f"Total backups: {len(all_backups)}") ``` -------------------------------- ### InstanceV1API — Manage CPU/GPU Instances Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Provides methods for managing Scaleway Instances, including listing, retrieving, creating, performing lifecycle actions, and deleting servers. It supports zone-level operations and automatic pagination. ```APIDOC ## `InstanceV1API` — Manage CPU/GPU Instances `InstanceV1API` (from `scaleway.instance.v1`) manages virtual machine Instances: create, list, start/stop/reboot, and take backups. Zone-level resource; use `default_zone` on the client or pass `zone=` explicitly. ```python from scaleway import Client from scaleway.instance.v1 import InstanceV1API from scaleway.instance.v1.types import ServerAction client = Client.from_config_file_and_env() api = InstanceV1API(client) # List all Instances in the default zone (single page) response = api.list_servers() for server in response.servers: print(server.id, server.name, server.state) # Fetch ALL pages at once (auto-pagination) all_servers = api.list_servers_all( commercial_type="GP1-S", tags=["prod", "web"], ) # Get a specific Instance server = api.get_server(server_id="11111111-1111-1111-1111-111111111111") print(server.server.public_ip) # Create a new Instance new_server = api._create_server( commercial_type="DEV1-S", image="ubuntu_jammy", name="my-web-server", protected=False, tags=["dev"], ) print("Created:", new_server.server.id) # Perform a lifecycle action: poweron / poweroff / reboot / backup / terminate api.server_action( server_id="11111111-1111-1111-1111-111111111111", action=ServerAction.reboot, ) # Delete an Instance api.delete_server(server_id="11111111-1111-1111-1111-111111111111") ``` ``` -------------------------------- ### Create a policy with IAM API Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Creates a policy with specified rules, granting access to specific projects and permission sets. Requires organization ID, policy name, and description. ```python policy = api.create_policy( name="instance-readonly", description="Read-only access to Instances", organization_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", rules=[ RuleSpecs( project_ids=["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"], permission_set_names=["InstancesReadOnly"], ) ], ) print("Policy ID:", policy.id) ``` -------------------------------- ### Record MongoDB Snapshot Test with VCR Source: https://github.com/scaleway/scaleway-sdk-python/blob/main/scaleway/scaleway/mongodb/v1/tests/README.md Use this command to run a specific MongoDB test and record its VCR cassette. Ensure Scaleway credentials are set and a target instance ID is provided. ```bash pytest -k test_create_snapshot_with_naive_expires_at_vcr ``` -------------------------------- ### Configure Logging for Scaleway SDK Source: https://github.com/scaleway/scaleway-sdk-python/blob/main/docs/index.md Configure the standard Python logging library to capture logs from the Scaleway SDK. This helps in debugging and monitoring SDK operations. ```default import logging logger = logging.getLogger("scaleway") logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG) ``` -------------------------------- ### Manage Managed Databases with RdbV1API Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Use `RdbV1API` to manage PostgreSQL and MySQL database instances, users, databases, backups, and read replicas. This includes listing engines, node types, creating instances, waiting for readiness, listing backups, and creating databases and users. ```python from scaleway import Client from scaleway.rdb.v1 import RdbV1API from scaleway.rdb.v1.types import ( CreateInstanceRequest, EndpointSpec, VolumeType, WaitForOptions, ) client = Client.from_config_file_and_env() api = RdbV1API(client) # List available database engines engines = api.list_database_engines_all() for engine in engines: print(engine.name, engine.versions) # List available node types (include disabled ones) node_types = api.list_node_types(include_disabled_types=False) # Create a PostgreSQL instance instance = api.create_instance( name="my-postgres-db", engine="PostgreSQL-15", node_type="DB-DEV-S", is_ha_cluster=False, disable_backup=False, volume_type=VolumeType.lssd, volume_size=10000000000, # 10 GB user_name="admin", password="S3cr3tP@ssword!", region="fr-par", tags=["production"], ) print("Instance ID:", instance.id) # Wait until instance is ready ready_instance = api.wait_for_instance( instance_id=instance.id, options=WaitForOptions(timeout=600), ) print("Ready:", ready_instance.status) # List all database backups for an instance backups = api.list_database_backups_all(instance_id=instance.id) for backup in backups: print(backup.id, backup.name, backup.status) # Create a database within the instance db = api.create_database(instance_id=instance.id, name="myapp_production") # Create a user user = api.create_user( instance_id=instance.id, name="app_user", password="AppP@ssword!", is_admin=False, ) ``` -------------------------------- ### Paginate Registry Namespaces (First Page) Source: https://github.com/scaleway/scaleway-sdk-python/blob/main/docs/index.md Retrieve only the first page of namespaces from the Scaleway registry. This is useful for quick checks or when only a subset of data is needed. ```default result = api.list_namespaces( # page=1, ) ``` -------------------------------- ### Paginate Registry Namespaces (All Pages) Source: https://github.com/scaleway/scaleway-sdk-python/blob/main/docs/index.md Retrieve all available pages of namespaces from the Scaleway registry. This method fetches all data, which can be resource-intensive for large datasets. ```default namespaces = api.list_namespaces_all() ``` -------------------------------- ### Async API - Kubernetes Cluster Management Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Manage Kubernetes clusters asynchronously, including creation and waiting for cluster readiness. ```APIDOC from scaleway_async.k8s.v1 import K8SV1API from scaleway_async.k8s.v1.types import CNI, WaitForOptions async def main(): client = Client.from_config_file_and_env() k8s_api = K8SV1API(client) clusters = await k8s_api.list_clusters_all(region="fr-par") # Create cluster asynchronously cluster = await k8s_api.create_cluster( type_="kapsule", name="async-cluster", description="Created via async SDK", version="1.30", cni=CNI.cilium, ) # Async wait for resource to reach a stable state ready = await k8s_api.wait_for_cluster( cluster_id=cluster.id, options=WaitForOptions(timeout=600, min_delay=5, max_delay=30), ) print("Cluster ready:", ready.status) asyncio.run(main()) ``` -------------------------------- ### Enable Debug Logging for SDK Requests/Responses Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Configure the 'scaleway' logger to `logging.DEBUG` to log detailed HTTP request and response information, including redacted secrets. Use `StreamHandler` to direct logs to the console. ```python import logging from scaleway import Client from scaleway.registry.v1 import RegistryV1API # Enable detailed HTTP-level debug logging logger = logging.getLogger("scaleway") handler = logging.StreamHandler() handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s")) logger.addHandler(handler) logger.setLevel(logging.DEBUG) client = Client.from_config_file_and_env() api = RegistryV1API(client) # The following call will produce DEBUG output showing: # --------------- Scaleway SDK REQUEST 1 --------------- # GET https://api.scaleway.com/registry/v1/regions/fr-par/namespaces?... # accept: application/json # x-auth-token: ***** <- automatically redacted # ------------------------------------------------------- # --------------- Scaleway SDK RESPONSE 1 --------------- # HTTP 200 OK # ... result = api.list_namespaces() ``` -------------------------------- ### Logging Debug Traces Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Details how to enable debug logging for the Scaleway SDK using Python's `logging` module to view detailed HTTP request and response information, including redacted secrets. ```APIDOC ## Logging — Debug Request/Response Traces The SDK uses Python's standard `logging` module under the `"scaleway"` logger name. Setting `DEBUG` level logs full HTTP request URLs, headers (with secret key redacted), and response bodies. ```python import logging from scaleway import Client from scaleway.registry.v1 import RegistryV1API # Enable detailed HTTP-level debug logging logger = logging.getLogger("scaleway") handler = logging.StreamHandler() handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s")) logger.addHandler(handler) logger.setLevel(logging.DEBUG) client = Client.from_config_file_and_env() api = RegistryV1API(client) # The following call will produce DEBUG output showing: # --------------- Scaleway SDK REQUEST 1 --------------- # GET https://api.scaleway.com/registry/v1/regions/fr-par/namespaces?... # accept: application/json # x-auth-token: ***** <- automatically redacted # ------------------------------------------------------- # --------------- Scaleway SDK RESPONSE 1 --------------- # HTTP 200 OK # ... result = api.list_namespaces() ``` ``` -------------------------------- ### Async registry and K8s operations Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Performs asynchronous operations on Scaleway Registry and Kubernetes services. Uses Python's asyncio and requires the `scaleway-async` package. ```python import asyncio from scaleway_async import Client from scaleway_async.registry.v1 import RegistryV1API from scaleway_async.k8s.v1 import K8SV1API from scaleway_async.k8s.v1.types import CNI, WaitForOptions async def main(): client = Client.from_config_file_and_env() # Async registry operations registry_api = RegistryV1API(client) namespaces = await registry_api.list_namespaces_all() for ns in namespaces: print(ns.id, ns.name) # Async K8s cluster management k8s_api = K8SV1API(client) clusters = await k8s_api.list_clusters_all(region="fr-par") # Create cluster asynchronously cluster = await k8s_api.create_cluster( type_="kapsule", name="async-cluster", description="Created via async SDK", version="1.30", cni=CNI.cilium, ) # Async wait for resource to reach a stable state ready = await k8s_api.wait_for_cluster( cluster_id=cluster.id, options=WaitForOptions(timeout=600, min_delay=5, max_delay=30), ) print("Cluster ready:", ready.status) asyncio.run(main()) ``` -------------------------------- ### Set user privileges on a database Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Sets user privileges for a specific database on a Scaleway instance. Requires instance, database name, user name, and permission level. ```python api.set_privilege( instance_id=instance.id, database_name="myapp_production", user_name="app_user", permission="all", ) ``` -------------------------------- ### Exception Handling Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Explains how to handle API errors using `ScalewayException` for general HTTP errors and `ValidationError` for specific validation failures, including client-side errors. ```APIDOC ## Exception Handling — `ScalewayException` / `ValidationError` All HTTP errors (4xx/5xx) raise `ScalewayException`. Validation failures (HTTP 400 with `"Validation Error"` message) raise `ValidationError`, which includes a `fields` dict with per-field messages. ```python from scaleway import Client from scaleway.instance.v1 import InstanceV1API from scaleway_core.api import ScalewayException, ValidationError client = Client.from_config_file_and_env() api = InstanceV1API(client) try: server = api.get_server(server_id="nonexistent-id-1234-5678-abcdefabcdef") except ValidationError as e: # HTTP 400: invalid field values print("Validation errors:", e.errors) # dict of field -> message print("HTTP status:", e.status_code) except ScalewayException as e: # All other HTTP errors (401, 403, 404, 500, ...) print("API error:", str(e)) # raw response body print("HTTP status:", e.status_code) except ValueError as e: # Client-side validation (bad access_key format, missing credentials, etc.) print("Client config error:", e) ``` ``` -------------------------------- ### Wait for Resource with Custom Options Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Use `wait_for_resource` for custom polling logic. Configure `WaitForOptions` for timeout, minimum, and maximum delay to manage polling frequency and duration. ```python from scaleway import Client from scaleway.rdb.v1 import RdbV1API from scaleway_core.utils.waiter import WaitForOptions, wait_for_resource from scaleway.rdb.v1.content import INSTANCE_TRANSIENT_STATUSES client = Client.from_config_file_and_env() api = RdbV1API(client) # Use the built-in wait_for_instance helper ready = api.wait_for_instance( instance_id="eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee", options=WaitForOptions( timeout=600, # max seconds to wait (default: 300) min_delay=5, # start polling every 5 seconds max_delay=60, # cap delay at 60 seconds (exponential backoff) ), ) print("Final state:", ready.status) # Custom waiter using low-level wait_for_resource instance = wait_for_resource( fetcher=api.get_instance, options=WaitForOptions( timeout=300, stop=lambda res: res.status not in INSTANCE_TRANSIENT_STATUSES, ), args={"instance_id": "eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee"}, ) ``` -------------------------------- ### Async API - Registry Operations Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Perform asynchronous operations on Scaleway Container Registry, such as listing namespaces. ```APIDOC import asyncio from scaleway_async import Client from scaleway_async.registry.v1 import RegistryV1API async def main(): client = Client.from_config_file_and_env() # Async registry operations registry_api = RegistryV1API(client) namespaces = await registry_api.list_namespaces_all() for ns in namespaces: print(ns.id, ns.name) asyncio.run(main()) ``` -------------------------------- ### IAM V1Alpha1API - API Keys Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Create and manage API keys for your IAM applications. API keys are used for programmatic access to Scaleway services. ```APIDOC # --- API Keys --- # Create an API key for an IAM application api_key = api.create_api_key( application_id="cccccccc-cccc-cccc-cccc-cccccccccccc", description="CI/CD pipeline key", default_project_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", ) print("Access Key:", api_key.access_key) print("Secret Key:", api_key.secret_key) # List all API keys keys = api.list_api_keys_all() ``` -------------------------------- ### RdbV1API - Managed Databases Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Manages managed relational database instances (PostgreSQL/MySQL), users, databases, backups, read replicas, and ACLs. This API is region-level. ```APIDOC ## `RdbV1API` — Managed Databases (PostgreSQL / MySQL) `RdbV1API` (from `scaleway.rdb.v1`) manages managed relational database instances, users, databases, backups, read replicas, and ACLs. Region-level resource. ### List Database Engines Lists all available managed database engines and their supported versions. Supports auto-pagination. ```python engines = api.list_database_engines_all() for engine in engines: print(engine.name, engine.versions) ``` ### List Node Types Lists available node types for database instances. ```python node_types = api.list_node_types(include_disabled_types=False) ``` ### Create Instance Creates a new managed database instance (e.g., PostgreSQL). ```python instance = api.create_instance( name="my-postgres-db", engine="PostgreSQL-15", node_type="DB-DEV-S", is_ha_cluster=False, disable_backup=False, volume_type=VolumeType.lssd, volume_size=10000000000, # 10 GB user_name="admin", password="S3cr3tP@ssword!", region="fr-par", tags=["production"], ) print("Instance ID:", instance.id) ``` ### Wait for Instance Waits until a database instance is ready, with configurable timeout options. ```python ready_instance = api.wait_for_instance( instance_id=instance.id, options=WaitForOptions(timeout=600), ) print("Ready:", ready_instance.status) ``` ### List Database Backups Lists all backups for a given database instance. Supports auto-pagination. ```python backups = api.list_database_backups_all(instance_id=instance.id) for backup in backups: print(backup.id, backup.name, backup.status) ``` ### Create Database Creates a new database within a managed instance. ```python db = api.create_database(instance_id=instance.id, name="myapp_production") ``` ### Create User Creates a new user for a managed database instance. ```python user = api.create_user( instance_id=instance.id, name="app_user", password="AppP@ssword!", is_admin=False, ) ``` ``` -------------------------------- ### K8SV1API - Kubernetes Kapsule and Kosmos Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Manages Kubernetes clusters, node pools, and cluster upgrades. This API is region-level. ```APIDOC ## `K8SV1API` — Kubernetes Kapsule and Kosmos `K8SV1API` (from `scaleway.k8s.v1`) manages Kubernetes clusters, node pools, and cluster upgrades. Region-level resource. ### List Clusters Lists all Kubernetes clusters. Supports auto-pagination. ```python clusters = api.list_clusters_all(region="fr-par") for cluster in clusters: print(cluster.id, cluster.name, cluster.status) ``` ### Create Cluster Creates a new Kubernetes cluster (Kapsule or Kosmos) with specified node pools and configurations. ```python pool_config = CreateClusterRequestPoolConfig( name="default-pool", node_type="DEV1-M", size=3, autoscaling=True, min_size=1, max_size=5, container_runtime=Runtime.containerd, root_volume_type=PoolVolumeType.sbs_15k, root_volume_size=20000000000, # 20 GB in bytes ) cluster = api.create_cluster( type_="kapsule", name="my-production-cluster", description="Production Kubernetes cluster", version="1.30", cni=CNI.cilium, region="fr-par", pools=[pool_config], tags=["production"], ) print("Cluster ID:", cluster.id) ``` ### Wait for Cluster Blocks until the cluster reaches a ready state, with configurable timeout and delay options. ```python ready_cluster = api.wait_for_cluster( cluster_id=cluster.id, options=WaitForOptions(timeout=600, min_delay=5, max_delay=60), ) print("Cluster status:", ready_cluster.status) ``` ### Install Kubeconfig Retrieves the kubeconfig file for accessing the cluster. ```python kubeconfig = api.install_cluster_kubeconfig(cluster_id=cluster.id) ``` ### Upgrade Cluster Upgrades an existing cluster to a specified Kubernetes version. ```python api.upgrade_cluster(cluster_id=cluster.id, version="1.31") ``` ### Delete Cluster Deletes a Kubernetes cluster. ```python api.delete_cluster(cluster_id=cluster.id, with_block_volumes=False) ``` ``` -------------------------------- ### RegistryV1API - Container Registry Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Manages Container Registry namespaces, images, and tags. This API is region-level. ```APIDOC ## `RegistryV1API` — Container Registry `RegistryV1API` (from `scaleway.registry.v1`) manages Container Registry namespaces, images, and tags. Region-level resource. ### List Namespaces Lists namespaces. Supports single-page retrieval and auto-pagination for all namespaces. ```python # List namespaces (single page) result = api.list_namespaces(region="fr-par") for ns in result.namespaces: print(ns.id, ns.name, ns.endpoint) # Fetch ALL namespaces (auto-pagination) all_namespaces = api.list_namespaces_all(project_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") ``` ### Get Namespace Fetches a specific namespace by its ID. ```python ns = api.get_namespace(namespace_id="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") ``` ### Create Namespace Creates a new container registry namespace. ```python new_ns = api.create_namespace( name="my-registry", description="Production images", is_public=False, ) print("Namespace endpoint:", new_ns.endpoint) ``` ### List Images Lists all images within a given namespace. Supports auto-pagination. ```python images = api.list_images_all(namespace_id=new_ns.id) for image in images: print(image.name, image.status) ``` ### Wait for Namespace Waits until a namespace reaches a non-transient status. ```python ready_ns = api.wait_for_namespace(namespace_id=new_ns.id) print("Ready:", ready_ns.status) ``` ### Update Image Visibility Updates the visibility of a specific image. ```python api.update_image( image_id="bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", visibility=ImageVisibility.public, ) ``` ``` -------------------------------- ### Utilize Region, Zone, and ScwFile Bridge Types Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Use `Region` and `Zone` for typed geography identifiers in API calls. `ScwFile` is used for binary file responses, providing content, name, and content type. ```python from scaleway_core.bridge import Region, Zone, ALL_REGIONS, ALL_ZONES, ScwFile # ALL_REGIONS and ALL_ZONES list all Scaleway regions/zones print(ALL_REGIONS) # e.g. ["fr-par", "nl-ams", "pl-waw", ...] print(ALL_ZONES) # e.g. ["fr-par-1", "fr-par-2", "nl-ams-1", ...] # Use in API calls from scaleway import Client from scaleway.k8s.v1 import K8SV1API client = Client.from_config_file_and_env() api = K8SV1API(client) # ScwFile is returned by download methods (binary content with name + content_type) kubeconfig: ScwFile = api.install_cluster_kubeconfig( cluster_id="ffffffff-ffff-ffff-ffff-ffffffffffff", region=Region("fr-par"), ) print("Filename:", kubeconfig.name) print("Content type:", kubeconfig.content_type) with open(f"/tmp/{kubeconfig.name}", "wb") as f: f.write(kubeconfig.content) ``` -------------------------------- ### IAM V1Alpha1API - Policies Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Define and manage policies to control access to Scaleway resources. Policies specify permissions granted to users or applications. ```APIDOC # --- Policies --- # Create a policy granting read-only access to Instances policy = api.create_policy( name="instance-readonly", description="Read-only access to Instances", organization_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", rules=[ RuleSpecs( project_ids=["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"], permission_set_names=["InstancesReadOnly"], ) ], ) print("Policy ID:", policy.id) # Delete an SSH key api.delete_ssh_key(ssh_key_id=ssh_key.id) ``` -------------------------------- ### IAM V1Alpha1API - SSH Keys Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Manage SSH keys within your Scaleway organization. This includes adding new keys and listing existing ones. ```APIDOC ## `IamV1Alpha1API` — Identity and Access Management `IamV1Alpha1API` (from `scaleway.iam.v1alpha1`) manages SSH keys, API keys, users, groups, applications, policies, and permission sets across Scaleway Organizations and Projects. ```python from scaleway import Client from scaleway.iam.v1alpha1 import IamV1Alpha1API from scaleway.iam.v1alpha1.types import ( CreatePolicyRequest, RuleSpecs, ListSSHKeysRequestOrderBy, ) client = Client.from_config_file_and_env() api = IamV1Alpha1API(client) # --- SSH Keys --- # Add a new SSH key ssh_key = api.create_ssh_key( public_key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... user@host", name="my-laptop-key", ) print("SSH Key ID:", ssh_key.id) # List all SSH keys (paginated) all_keys = api.list_ssh_keys_all( order_by=ListSSHKeysRequestOrderBy.name_asc, disabled=False, ) ``` ``` -------------------------------- ### Handle Scaleway API Exceptions Source: https://context7.com/scaleway/scaleway-sdk-python/llms.txt Catch `ScalewayException` for general HTTP errors (4xx/5xx) and `ValidationError` for specific 400 errors with validation issues. `ValidationError` provides a `fields` dictionary for per-field error messages. ```python from scaleway import Client from scaleway.instance.v1 import InstanceV1API from scaleway_core.api import ScalewayException, ValidationError client = Client.from_config_file_and_env() api = InstanceV1API(client) try: server = api.get_server(server_id="nonexistent-id-1234-5678-abcdefabcdef") except ValidationError as e: # HTTP 400: invalid field values print("Validation errors:", e.errors) # dict of field -> message print("HTTP status:", e.status_code) except ScalewayException as e: # All other HTTP errors (401, 403, 404, 500, ...) print("API error:", str(e)) # raw response body print("HTTP status:", e.status_code) except ValueError as e: # Client-side validation (bad access_key format, missing credentials, etc.) print("Client config error:", e) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.