### Set Up Environment and Install Dependencies Source: https://github.com/verda-cloud/sdk-python/blob/master/CONTRIBUTING.md Synchronize the local environment and install all necessary project dependencies using uv. ```bash uv sync ``` -------------------------------- ### Install Verda Python SDK Source: https://github.com/verda-cloud/sdk-python/blob/master/README.md Install the Verda Python SDK using pip or uv. ```bash pip install verda ``` ```bash uv add verda ``` -------------------------------- ### SGLang Deployment Example Script Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/sglang.md This script demonstrates deploying a SGLang server with a Hugging Face model using the Verda API. It includes setup, deployment, monitoring, testing, and cleanup. ```python # Copyright 2026 Verda Cloud Oy # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Example script demonstrating SGLang model deployment using the Verda API. This script provides an example of deploying a SGLang server with deepseek-ai/deepseek-llm-7b-chat model, including creation, monitoring, testing, and cleanup. """ import json import os import signal import sys import time from datetime import datetime from verda import VerdaClient from verda.containers import ( ComputeResource, Container, ContainerDeploymentStatus, Deployment, EntrypointOverridesSettings, EnvVar, EnvVarType, HealthcheckSettings, QueueLoadScalingTrigger, ScalingOptions, ScalingPolicy, ScalingTriggers, UtilizationScalingTrigger, ) from verda.exceptions import APIException CURRENT_TIMESTAMP = datetime.now().strftime('%Y%m%d-%H%M%S').lower() # e.g. 20250403-120000 # Configuration constants DEPLOYMENT_NAME = f'sglang-deployment-example-{CURRENT_TIMESTAMP}' SGLANG_IMAGE_URL = 'docker.io/lmsysorg/sglang:v0.4.1.post6-cu124' DEEPSEEK_MODEL_PATH = 'deepseek-ai/deepseek-llm-7b-chat' HF_SECRET_NAME = 'huggingface-token' ``` -------------------------------- ### Container Deployment Example with Environment Variables Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Shows how to configure container deployments using environment variables and consistent credential loading. ```python # Example usage (assuming deployment configuration) ``` -------------------------------- ### Install Verda SDK from Source Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/installation.md Install the Verda SDK after cloning the repository. This method is useful for developers who need to work with the latest development code or contribute to the SDK. ```bash python3 setup.py install ``` -------------------------------- ### Local Manual Testing Setup Source: https://github.com/verda-cloud/sdk-python/blob/master/README.md Create a Python file for local manual testing and initialize the Verda client. ```python # example.py from verda import VerdaClient CLIENT_SECRET = 'secret' CLIENT_ID = 'your-id' # Create client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) ``` -------------------------------- ### Create, Get, and Delete Startup Scripts Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/startup_scripts.md This snippet shows how to create a new startup script, retrieve all scripts, get a specific script by ID, and delete a script. Ensure the VERDA_CLIENT_SECRET environment variable is set. ```python import os from verda import VerdaClient # Get client secret from environment variable CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi' # Replace with your client ID # Create datcrunch client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Create new startup script bash_script = """echo this is a test script for serious cat business # create a cats folder mkdir cats && cd cats # download a cat picture curl https://http.cat/200 --output cat.jpg """ script = verda.startup_scripts.create("catty businness", bash_script) # Print new startup script id, name, script code print(script.id) print(script.name) print(script.script) # Get all startup scripts all_scripts = verda.startup_scripts.get() # Get a single startup script by id some_script = verda.startup_scripts.get_by_id(script.id) # Delete startup script by id verda.startup_scripts.delete_by_id(script.id) ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/verda-cloud/sdk-python/blob/master/README.md Clone the Verda SDK repository and install local development dependencies using uv. ```bash git clone git@github.com:verda-cloud/sdk-python.git cd sdk-python uv sync ``` -------------------------------- ### Get and Update Container Scaling Options Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/scaling.md This snippet shows how to fetch current scaling configurations for a deployment and then update them with new settings. It includes examples of setting replica limits, cooldown delays, and different scaling triggers. ```python from verda.client import VerdaClient from verda.data.containers import ScalingOptions, ScalingPolicy, ScalingTriggers, QueueLoadScalingTrigger, UtilizationScalingTrigger from verda.exceptions import APIException CLIENT_ID = "your_client_id" CLIENT_SECRET = "your_client_secret" DEPLOYMENT_NAME = "your_deployment_name" # Initialize client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) try: # Get current scaling options scaling_options = verda.containers.get_deployment_scaling_options(DEPLOYMENT_NAME) print('Current scaling configuration:\n') print(f'Min replicas: {scaling_options.min_replica_count}') print(f'Max replicas: {scaling_options.max_replica_count}') print(f'Scale-up delay: {scaling_options.scale_up_policy.delay_seconds} seconds') print(f'Scale-down delay: {scaling_options.scale_down_policy.delay_seconds} seconds') print(f'Queue message TTL: {scaling_options.queue_message_ttl_seconds} seconds') print(f'Concurrent requests per replica: {scaling_options.concurrent_requests_per_replica}') print('Scaling Triggers:') print(f' Queue load threshold: {scaling_options.scaling_triggers.queue_load.threshold}') if scaling_options.scaling_triggers.cpu_utilization: print( f' CPU utilization enabled: {scaling_options.scaling_triggers.cpu_utilization.enabled}' ) print( f' CPU utilization threshold: {scaling_options.scaling_triggers.cpu_utilization.threshold}%%' ) if scaling_options.scaling_triggers.gpu_utilization: print( f' GPU utilization enabled: {scaling_options.scaling_triggers.gpu_utilization.enabled}' ) if scaling_options.scaling_triggers.gpu_utilization.threshold: print( f' GPU utilization threshold: {scaling_options.scaling_triggers.gpu_utilization.threshold}%%' ) # Create scaling options using ScalingOptions dataclass scaling_options = ScalingOptions( min_replica_count=1, max_replica_count=5, scale_down_policy=ScalingPolicy(delay_seconds=600), # Longer cooldown period scale_up_policy=ScalingPolicy(delay_seconds=0), # Quick scale-up queue_message_ttl_seconds=500, concurrent_requests_per_replica=50, # LLMs can handle concurrent requests scaling_triggers=ScalingTriggers( queue_load=QueueLoadScalingTrigger(threshold=1.0), cpu_utilization=UtilizationScalingTrigger(enabled=True, threshold=75), gpu_utilization=UtilizationScalingTrigger( enabled=False # Disable GPU utilization trigger ), ), ) # Update scaling options updated_options = verda.containers.update_deployment_scaling_options( DEPLOYMENT_NAME, scaling_options ) print('\nUpdated scaling configuration:\n') print(f'Min replicas: {updated_options.min_replica_count}') print(f'Max replicas: {updated_options.max_replica_count}') print(f'Scale-up delay: {updated_options.scale_up_policy.delay_seconds} seconds') print(f'Scale-down delay: {updated_options.scale_down_policy.delay_seconds} seconds') print(f'Queue message TTL: {updated_options.queue_message_ttl_seconds} seconds') print(f'Concurrent requests per replica: {updated_options.concurrent_requests_per_replica}') print('Scaling Triggers:') print(f' Queue load threshold: {updated_options.scaling_triggers.queue_load.threshold}') if updated_options.scaling_triggers.cpu_utilization: print( f' CPU utilization enabled: {updated_options.scaling_triggers.cpu_utilization.enabled}' ) print( f' CPU utilization threshold: {updated_options.scaling_triggers.cpu_utilization.threshold}%%' ) if updated_options.scaling_triggers.gpu_utilization: print( f' GPU utilization enabled: {updated_options.scaling_triggers.gpu_utilization.enabled}' ) if updated_options.scaling_triggers.gpu_utilization.threshold: print( f' GPU utilization threshold: {updated_options.scaling_triggers.gpu_utilization.threshold}%%' ) except APIException as e: print(f'Error updating scaling options: {e}') except Exception as e: print(f'Unexpected error: {e}') ``` -------------------------------- ### Inference Endpoint Example Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Demonstrates calling the inference endpoint with a minimal client to get status and results, including support for asynchronous inference. ```python # Example usage (assuming client and endpoint details are configured) ``` -------------------------------- ### Create Verda Client and Manage Instances Source: https://github.com/verda-cloud/sdk-python/blob/master/README.md Example demonstrating how to create a Verda client instance using environment variables, retrieve SSH keys, create a new instance, and then delete it. ```python import os from verda import VerdaClient from verda.constants import Actions # Get credentials from environment variables CLIENT_ID = os.environ['VERDA_CLIENT_ID'] CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] # Create client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Get all SSH keys ssh_keys = [key.id for key in verda.ssh_keys.get()] # Create a new instance instance = verda.instances.create(instance_type='1V100.6V', image='ubuntu-24.04-cuda-12.8-open-docker', ssh_key_ids=ssh_keys, hostname='example', description='example instance') # Delete instance verda.instances.action(instance.id, Actions.DELETE) ``` -------------------------------- ### Install Latest Stable Release using Pip Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/installation.md Use pip to install the latest stable version of the Verda SDK. This is the recommended method for most users. ```bash pip install verda ``` -------------------------------- ### Install Verda Package Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Install the Verda Python package using pip. This is the recommended way to use the Verda SDK. ```shell uv add verda pip install verda ``` -------------------------------- ### Install Datacrunch Package (Deprecated) Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Install the deprecated `datacrunch` Python package. It is recommended to migrate to the `verda` package. ```shell uv add datacrunch pip install datacrunch ``` -------------------------------- ### Container Deployment Management Example Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/deployments.md This Python script demonstrates the full lifecycle of container deployments using the Verda API. It covers creation, monitoring, scaling, and cleanup. Ensure VERDA_CLIENT_ID and VERDA_CLIENT_SECRET environment variables are set. ```python # Copyright 2026 Verda Cloud Oy # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Example script demonstrating container deployment management using the Verda API. This script provides a comprehensive example of container deployment lifecycle, including creation, monitoring, scaling, and cleanup. """ import os import time from verda import VerdaClient from verda.containers import ( ComputeResource, Container, ContainerDeploymentStatus, ContainerRegistrySettings, Deployment, EnvVar, EnvVarType, GeneralStorageMount, HealthcheckSettings, QueueLoadScalingTrigger, ScalingOptions, ScalingPolicy, ScalingTriggers, SecretMount, SharedFileSystemMount, UtilizationScalingTrigger, ) from verda.exceptions import APIException # Configuration constants DEPLOYMENT_NAME = 'my-deployment' IMAGE_NAME = 'your-image-name:version' # Get client secret and id from environment variables CLIENT_ID = os.environ.get('VERDA_CLIENT_ID') CLIENT_SECRET = os.environ.get('VERDA_CLIENT_SECRET') ``` -------------------------------- ### Clone Verda SDK Repository from GitHub Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/installation.md Download the source files of the Verda SDK from the official GitHub repository. This is a prerequisite for installing from source. ```bash git clone https://github.com/verda-cloud/sdk-python.git ``` -------------------------------- ### Clone Repository Source: https://github.com/verda-cloud/sdk-python/blob/master/CONTRIBUTING.md Clone your forked repository locally to start making changes. ```bash git clone git@github.com:{your_username}/sdk-python.git cd sdk-python ``` -------------------------------- ### Add GitHub Container Registry Credentials Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/registry_credentials.md This example shows how to add credentials for GitHub Container Registry. You will need your GitHub username and a personal access token. ```python # Example 2: GitHub Container Registry Credentials github_creds = GithubCredentials( name='my-github-creds', username='your-github-username', access_token='your-github-token', ) verda.containers.add_registry_credentials(github_creds) print('Created GitHub credentials') ``` -------------------------------- ### Manage Container Environment Variables Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/environment_variables.md Demonstrates the full lifecycle of managing environment variables for a container deployment. Includes getting, adding, updating, and deleting variables, as well as creating and using secrets. ```python # Copyright 2026 Verda Cloud Oy # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ This example demonstrates how to manage environment variables for container deployments. It shows how to: 1. Get environment variables for a deployment 2. Add new environment variables to a container 3. Update existing environment variables 4. Delete environment variables """ import os from verda import VerdaClient from verda.containers import EnvVar, EnvVarType # Get client secret and id from environment variables CLIENT_ID = os.environ.get('VERDA_CLIENT_ID') CLIENT_SECRET = os.environ.get('VERDA_CLIENT_SECRET') # Initialize Verda client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Example deployment and container names DEPLOYMENT_NAME = 'my-deployment' CONTAINER_NAME = 'main' def print_env_vars(env_vars: dict[str, list[EnvVar]]) -> None: """Helper function to print environment variables""" print('\nCurrent environment variables:') for container_name, ev in env_vars.items(): print(f'\nContainer: {container_name}') for var in ev: print(f' {var.name}: {var.value_or_reference_to_secret} ({var.type})') def main(): # First, let's get the current environment variables print('Getting current environment variables...') env_vars = verda.containers.get_deployment_environment_variables(DEPLOYMENT_NAME) print_env_vars(env_vars) # Create a new secret secret_name = 'my-secret-key' verda.containers.create_secret(secret_name, 'my-secret-value') # Add new environment variables print('\nAdding new environment variables...') new_env_vars = [ EnvVar( name='API_KEY', value_or_reference_to_secret=secret_name, type=EnvVarType.SECRET, ), EnvVar(name='DEBUG', value_or_reference_to_secret='true', type=EnvVarType.PLAIN), ] env_vars = verda.containers.add_deployment_environment_variables( deployment_name=DEPLOYMENT_NAME, container_name=CONTAINER_NAME, env_vars=new_env_vars, ) print_env_vars(env_vars) # Update existing environment variables print('\nUpdating environment variables...') updated_env_vars = [ EnvVar(name='DEBUG', value_or_reference_to_secret='false', type=EnvVarType.PLAIN), ] env_vars = verda.containers.update_deployment_environment_variables( deployment_name=DEPLOYMENT_NAME, container_name=CONTAINER_NAME, env_vars=updated_env_vars, ) print_env_vars(env_vars) # Delete environment variables print('\nDeleting environment variables...') env_vars = verda.containers.delete_deployment_environment_variables( deployment_name=DEPLOYMENT_NAME, container_name=CONTAINER_NAME, env_var_names=['DEBUG'], ) print_env_vars(env_vars) if __name__ == '__main__': main() ``` -------------------------------- ### Common Bash Commands for Verda Cloud SDK Project Source: https://github.com/verda-cloud/sdk-python/blob/master/CLAUDE.md These commands are used for managing dependencies, running tests, linting, and formatting the project. Ensure `uv` is installed and in your PATH. ```bash uv sync # install dependencies ``` ```bash uv run pytest # run all tests (unit + integration) ``` ```bash uv run pytest tests/unit_tests # run unit tests only ``` ```bash uv run ruff check # lint ``` ```bash uv run ruff format --check # check formatting ``` ```bash uv run ruff format # auto-format ``` -------------------------------- ### Delete All Registry Credentials Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/registry_credentials.md This example shows how to delete all previously added registry credentials by their names. Ensure you use the correct names for deletion. ```python # Delete all registry credentials verda.containers.delete_registry_credentials('my-dockerhub-creds') verda.containers.delete_registry_credentials('my-github-creds') verda.containers.delete_registry_credentials('my-gcr-creds') verda.containers.delete_registry_credentials('my-aws-ecr-creds') verda.containers.delete_registry_credentials('my-custom-registry-creds') ``` -------------------------------- ### Replace Module and Class Names Source: https://github.com/verda-cloud/sdk-python/blob/master/MIGRATION.md Update import statements and client instantiation to use 'verda' module and 'VerdaClient' class. This example shows the typical try-except block for API interactions. ```python # Before from datacrunch import DataCrunchClient from datacrunch.exceptions import APIException try: datacrunch = DataCrunchClient(...) datacrunch.instances.create(...) except APIException as exception: print('error', exception) # After from verda import VerdaClient from verda.exceptions import APIException try: verda = VerdaClient(...) verda.instances.create(...) except APIException as e: print('error', e) ``` -------------------------------- ### Create, Get, and Delete Fileset Secrets Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/fileset_secrets.md This snippet shows how to create a fileset secret from local file paths, retrieve all fileset secrets, and then delete the created secret. Ensure Verda client ID and secret are set as environment variables. ```python # Copyright 2026 Verda Cloud Oy # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # you may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os from verda import VerdaClient # Fileset secrets are a way to mount sensitive files like API keys, certs, and credentials securely inside a container, without hardcoding them in the image or env vars. # This example demonstrates how to create a fileset secret containing two files from your local filesystem # Get client secret and id from environment variables CLIENT_ID = os.environ.get('VERDA_CLIENT_ID') CLIENT_SECRET = os.environ.get('VERDA_CLIENT_SECRET') # Initialize the client with your credentials verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Define the secret name and the file paths from your local filesystem where this script is running SECRET_NAME = 'my-fileset-secret' RELATIVE_FILE_PATH = './relative-path/file1.txt' ABSOLUTE_FILE_PATH = '/home/username/absolute-path/file2.json' # Create the fileset secret that has 2 files fileset_secret = verda.containers.create_fileset_secret_from_file_paths( secret_name=SECRET_NAME, file_paths=[RELATIVE_FILE_PATH, ABSOLUTE_FILE_PATH] ) # Get the secret secrets = verda.containers.get_fileset_secrets() print(secrets) # Delete the secret verda.containers.delete_fileset_secret(secret_name=SECRET_NAME) ``` -------------------------------- ### Get Datacrunch Package Version Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Use importlib.metadata.version() to retrieve the installed version of the datacrunch package. ```python from importlib.metadata import version print(version('datacrunch')) ``` -------------------------------- ### Generate Documentation Locally Source: https://github.com/verda-cloud/sdk-python/blob/master/README.md Navigate to the docs directory and build the HTML documentation using make. ```bash cd docs make html ``` -------------------------------- ### Create and Test SGLang Deployment Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/sglang.md This snippet shows the complete process of setting up a SGLang deployment, including defining compute resources, scaling options, and then testing the deployment's /get_model_info and /v1/completions endpoints. It also demonstrates handling both synchronous and streaming inference requests. ```python import os import sys import json from sglang.sdk.utils import ( # noqa cleanup_resources, # noqa wait_for_deployment_health, # noqa ) from verda.containers import Container, ComputeResource, Deployment, UtilizationScalingTrigger # Define constants DEPLOYMENT_NAME = 'sglang-deployment' DEEPSEEK_MODEL_PATH = 'deepseek-ai/deepseek-coder-1.3b-instruct' # Initialize Verda client verda = verda.Client() try: # Define the container for the SGLang model container = Container( name='sglang-container', image='sglang/sglang-server:latest', ports=[8000], env={'MODEL_PATH': DEEPSEEK_MODEL_PATH}, resources=Container.Resources( gpu_utilization=UtilizationScalingTrigger(enabled=True, threshold=90), ), ) # Set compute settings. For a 7B model, General Compute (24GB VRAM) is sufficient compute = ComputeResource(name='General Compute', size=1) # Create deployment object (no need to provide container_registry_settings because it's public) deployment = Deployment( name=DEPLOYMENT_NAME, containers=[container], compute=compute, scaling=scaling_options, is_spot=False, ) # Create the deployment created_deployment = verda.containers.create_deployment(deployment) print(f'Created deployment: {created_deployment.name}') print('This could take several minutes while the model is downloaded and the server starts...') # Wait for deployment to be healthy if not wait_for_deployment_health(verda, DEPLOYMENT_NAME): print('Deployment health check failed') cleanup_resources(verda) sys.exit(1) # Test the deployment with a simple request print('\nTesting the deployment...') try: # Test model info endpoint print( 'Testing /get_model_info endpoint by making a sync GET request to the SGLang server...' ) model_info_response = created_deployment._inference_client.get(path='/get_model_info') print('Model info endpoint is working!') print(f'Response: {model_info_response}') # Test completions endpoint print('\nTesting completions API...') completions_data = { 'model': DEEPSEEK_MODEL_PATH, 'prompt': 'Is consciousness fundamentally computational, or is there something more to subjective experience that cannot be reduced to information processing?', 'max_tokens': 128, 'temperature': 0.7, 'top_p': 0.9, } # Make a sync inference request to the SGLang server completions_response = created_deployment.run_sync( completions_data, path='/v1/completions', ) print('Completions API is working!') print(f'Response: {completions_response.output()}\n') # Make a stream sync inference request to the SGLang server completions_response_stream = created_deployment.run_sync( {**completions_data, 'stream': True}, path='/v1/completions', stream=True ) print('Stream completions API is working!') # Print the streamed response for line in completions_response_stream.stream(as_text=True): if line: line = line.decode('utf-8') if line.startswith('data:'): data = line[5:] # Remove 'data: ' prefix if data == '[DONE]': break try: event_data = json.loads(data) token_text = event_data['choices'][0]['text'] # Print token immediately to show progress print(token_text, end='', flush=True) except json.JSONDecodeError: continue except Exception as e: print(f'Error testing deployment: {e}') # Cleanup or keep running based on user input keep_running = input('\nDo you want to keep the deployment running? (y/n): ') if keep_running.lower() != 'y': cleanup_resources(verda) else: print(f"Deployment {DEPLOYMENT_NAME} is running. Don't forget to delete it when finished.") print('You can delete it from the Verda dashboard or by running:') print(f"verda.containers.delete('{DEPLOYMENT_NAME}')") except Exception as e: print(f'Unexpected error: {e}') # Attempt cleanup even if there was an error try: cleanup_resources(verda) except Exception as cleanup_error: print(f'Error during cleanup after failure: {cleanup_error}') sys.exit(1) ``` -------------------------------- ### List Available Instance and Image Types Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/index.md This snippet shows how to fetch information about all available instance types and operating system images that can be used for deploying new instances. ```python instance_types = verda.instance_types.get() images_types = verda.images.get() ``` -------------------------------- ### Create Instance with Attached Volumes Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/instances_and_volumes.md Create an instance and attach additional HDD and NVMe volumes. Ensure you have your client ID and secret configured, and SSH keys retrieved. ```python import os from verda import VerdaClient from verda.constants import Actions, VolumeTypes # Get client secret from environment variable CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi' # Replace with your client ID # Create datcrunch client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Get some volume type constants NVMe = VolumeTypes.NVMe HDD = VolumeTypes.HDD EXISTING_OS_VOLUME_ID = '81e45bf0-5da2-412b-97d7-c20a7564fca0' EXAMPLE_VOLUME_ID = '225dde24-ae44-4787-9224-2b9f56f44394' EXAMPLE_INSTANCE_ID = '1eeabba4-caf7-4b4a-9143-0107034cc7f5' # Get all SSH keys ssh_keys = verda.ssh_keys.get() ssh_keys_ids = list(map(lambda ssh_key: ssh_key.id, ssh_keys)) # Create instance with extra attached volumes instance_with_extra_volumes = verda.instances.create(instance_type='1V100.6V', image='ubuntu-24.04-cuda-12.8-open-docker', ssh_key_ids=ssh_keys, hostname='example', description='example instance', volumes=[ {"type": HDD, "name": "volume-1", "size": 95}, {"type": NVMe, "name": "volume-2", "size": 95}, ]) ``` -------------------------------- ### Create, Shutdown, and Hibernate Verda Instance Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/instance_actions.md This snippet shows how to create a new instance, wait for it to be in a running state, shut it down, and then hibernate it. It includes error handling for actions taken before the instance is ready. ```python import os import time from verda import VerdaClient from verda.exceptions import APIException # Get client secret from environment variable CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi' # Replace with your client ID # Create datcrunch client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Get all SSH keys ssh_keys = verda.ssh_keys.get() ssh_keys_ids = list(map(lambda ssh_key: ssh_key.id, ssh_keys)) # Create a new 1V100.6V instance instance = verda.instances.create(instance_type='1V100.6V', image='ubuntu-24.04-cuda-12.8-open-docker', ssh_key_ids=ssh_keys_ids, hostname='example', description='example instance') print(instance.id) # Try to shutdown instance right away, # encounter an error (because it's still provisioning) try: verda.instances.action(instance.id, verda.actions.SHUTDOWN) except APIException as exception: print(exception) # we were too eager... # Wait until instance is running (check every 30sec), only then shut it down while(instance.status != verda.instance_status.RUNNING): time.sleep(30) instance = verda.instances.get_by_id(instance.id) # Shutdown! try: verda.instances.action(instance.id, verda.actions.SHUTDOWN) except APIException as exception: print(exception) # no exception this time # Wait until instance is offline (check every 30sec), only then hibernate while(instance.status != verda.instance_status.OFFLINE): time.sleep(30) instance = verda.instances.get_by_id(instance.id) # Hibernate the instance try: verda.instances.action(instance.id, verda.actions.HIBERNATE) except APIException as exception: print(exception) ``` -------------------------------- ### Initialize DataCrunch Client and Create Instance (Deprecated) Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Initialize the `DataCrunchClient` and create an instance. This usage is deprecated and should be replaced with the `VerdaClient`. ```python from datacrunch import DataCrunchClient datacrunch = DataCrunchClient(...) datacrunch.instances.create(...) ``` -------------------------------- ### List Verda Resources Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/index.md This snippet demonstrates how to retrieve lists of all existing instances, SSH keys, and startup scripts available in your Verda account. ```python instances = verda.instances.get() keys = verda.ssh_keys.get() scripts = verda.startup_scripts.get() ``` -------------------------------- ### Deploy Instance with Existing Volumes Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Enables deploying a new instance that is pre-configured with existing volumes. ```python # Example usage (assuming instance deployment with volume configuration) ``` -------------------------------- ### Initialize Verda Client and Create Instance Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Initialize the Verda client and create an instance using the new `verda` package. This replaces the deprecated `DataCrunchClient`. ```python from verda import VerdaClient verda = VerdaClient(...) verda.instances.create(...) ``` -------------------------------- ### Create Instance with Existing OS Volume as Image Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/instances_and_volumes.md Create an instance using an existing OS volume ID as the image. This is useful for deploying pre-configured operating system volumes. ```python instance_with_existing_os_volume = verda.instances.create(instance_type='1V100.6V', image=EXISTING_OS_VOLUME_ID, ssh_key_ids=ssh_keys, hostname='example', description='example instance') ``` -------------------------------- ### Set Environment Variable for Client Secret Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples.md This command sets the VERDA_CLIENT_SECRET environment variable on Linux systems. Ensure this variable is set before running SDK examples that require authentication. ```default export VERDA_CLIENT_SECRET=Z4CZq02rdwdB7ISV0k4Z2gtwAFKiyvr2U1l0KDIeYi ``` -------------------------------- ### Create and Manage Container Deployment Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/deployments.md Demonstrates the full lifecycle of a container deployment, from initialization and creation to health checks, scaling updates, and cleanup. This snippet is useful for understanding how to programmatically manage deployments. ```python import time from verda.client import VerdaClient from verda.client.containers import Container, ContainerDeploymentStatus, Deployment, ContainerRegistrySettings, ComputeResource, ScalingOptions, ScalingPolicy, ScalingTriggers, QueueLoadScalingTrigger, UtilizationScalingTrigger from verda.client.containers.models import HealthcheckSettings, GeneralStorageMount, SecretMount, SharedFileSystemMount, EnvVar, EnvVarType from verda.exceptions import APIException # Placeholder constants - replace with actual values CLIENT_ID = "your_client_id" CLIENT_SECRET = "your_client_secret" IMAGE_NAME = "your_docker_image" DEPLOYMENT_NAME = "my-test-deployment" verda = None def wait_for_deployment_health( client: VerdaClient, deployment_name: str, max_attempts: int = 10, delay: int = 30, ) -> bool: """Wait for deployment to reach healthy status. Args: client: Verda API client deployment_name: Name of the deployment to check max_attempts: Maximum number of status checks delay: Delay between checks in seconds Returns: bool: True if deployment is healthy, False otherwise """ for _attempt in range(max_attempts): try: status = client.containers.get_deployment_status(deployment_name) print(f'Deployment status: {status}') if status == ContainerDeploymentStatus.HEALTHY: return True time.sleep(delay) except APIException as e: print(f'Error checking deployment status: {e}') return False return False def cleanup_resources(client: VerdaClient) -> None: """Clean up all created resources. Args: client: Verda API client """ try: # Delete deployment client.containers.delete_deployment(DEPLOYMENT_NAME) print('Deployment deleted') except APIException as e: print(f'Error during cleanup: {e}') def main() -> None: """Main function demonstrating deployment lifecycle management.""" try: # Initialize client global verda verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Create container configuration container = Container( image=IMAGE_NAME, exposed_port=80, healthcheck=HealthcheckSettings(enabled=True, port=80, path='/health'), volume_mounts=[ GeneralStorageMount(mount_path='/data'), # Optional: Fileset secret SecretMount( mount_path='/path/to/mount', secret_name='my-fileset-secret', # This fileset secret must be created beforehand ), # Optional: Mount an existing shared filesystem volume SharedFileSystemMount(mount_path='/sfs', volume_id=''), ], env=[ # Secret environment variables needed to be added beforehand EnvVar( name='HF_TOKEN', # This is a reference to a secret already created value_or_reference_to_secret='hf-token', type=EnvVarType.SECRET, ), # Plain environment variables can be added directly EnvVar( name='VERSION', value_or_reference_to_secret='1.5.2', type=EnvVarType.PLAIN, ), ], ) # Create scaling configuration scaling_options = ScalingOptions( min_replica_count=1, max_replica_count=5, scale_down_policy=ScalingPolicy(delay_seconds=300), scale_up_policy=ScalingPolicy(delay_seconds=300), queue_message_ttl_seconds=500, concurrent_requests_per_replica=1, scaling_triggers=ScalingTriggers( queue_load=QueueLoadScalingTrigger(threshold=1), cpu_utilization=UtilizationScalingTrigger(enabled=True, threshold=80), gpu_utilization=UtilizationScalingTrigger(enabled=True, threshold=80), ), ) # Create registry and compute settings registry_settings = ContainerRegistrySettings(is_private=False) compute = ComputeResource(name='General Compute', size=1) # Create deployment object deployment = Deployment( name=DEPLOYMENT_NAME, container_registry_settings=registry_settings, containers=[container], compute=compute, scaling=scaling_options, is_spot=False, ) # Create the deployment created_deployment = verda.containers.create_deployment(deployment) print(f'Created deployment: {created_deployment.name}') # Wait for deployment to be healthy if not wait_for_deployment_health(verda, DEPLOYMENT_NAME): print('Deployment health check failed') cleanup_resources(verda) return # Update scaling configuration try: deployment = verda.containers.get_deployment_by_name(DEPLOYMENT_NAME) # Create new scaling options with increased replica counts deployment.scaling = ScalingOptions( min_replica_count=2, max_replica_count=10, scale_down_policy=ScalingPolicy(delay_seconds=300), scale_up_policy=ScalingPolicy(delay_seconds=300), queue_message_ttl_seconds=500, concurrent_requests_per_replica=1, ) updated_deployment = verda.containers.update_deployment(deployment) print(f'Updated deployment scaling: {updated_deployment.scaling}') except APIException as e: print(f'Error updating deployment: {e}') except APIException as e: print(f'An error occurred: {e}') finally: # Clean up resources if the verda client was initialized if verda: cleanup_resources(verda) if __name__ == '__main__': main() ``` -------------------------------- ### Create Instance with Custom OS Volume Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/instances_and_volumes.md Create an instance with a custom name and size for its OS volume. This allows for more control over the operating system disk. ```python instance_with_custom_os_volume = verda.instances.create(instance_type='1V100.6V', image='ubuntu-24.04-cuda-12.8-open-docker', ssh_key_ids=ssh_keys, hostname='example', description='example instance', os_volume={ "name": "OS volume", "size": 95, }) ``` -------------------------------- ### Run Local Manual Test Source: https://github.com/verda-cloud/sdk-python/blob/master/README.md Execute a Python script for local manual testing using uv. ```bash uv run python example.py ``` -------------------------------- ### Instance and Volume Creation with Location Code Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Refactored code to use `location_code` instead of `location` when creating an instance or a volume. ```python # Example usage (assuming instance or volume creation calls) ``` -------------------------------- ### Minimal Async Inference Client Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/containers/inference_minimal_async.md This snippet shows how to initialize an `InferenceClient` using only an inference key and an endpoint base URL, which are retrieved from environment variables. It then makes an asynchronous inference request and polls for its completion. ```python # Copyright 2026 Verda Cloud Oy # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os from time import sleep from verda.inference_client import AsyncStatus, InferenceClient # Get inference key and endpoint base url from environment variables INFERENCE_KEY = os.environ.get('VERDA_INFERENCE_KEY') BASE_URL = os.environ.get('VERDA_BASE_URL') # Create an inference client that uses only the inference key, without client credentials inference_client = InferenceClient( inference_key=INFERENCE_KEY, endpoint_base_url=BASE_URL, ) # Make an asynchronous request to the endpoint # This example demonstrates calling a SGLang deployment which serves LLMs using an OpenAI-compatible API format data = { 'model': 'deepseek-ai/deepseek-llm-7b-chat', 'prompt': 'Is consciousness fundamentally computational, or is there something more to subjective experience that cannot be reduced to information processing?', 'max_tokens': 128, 'temperature': 0.7, 'top_p': 0.9, } # Run the request asynchronously using the inference client async_inference_execution = inference_client.run(data=data, path='v1/completions') # Poll for status until completion while async_inference_execution.status() != AsyncStatus.Completed: print(async_inference_execution.status_json()) sleep(5) # Print the response print(async_inference_execution.output()) ``` -------------------------------- ### Conditional Instance Deployment Source: https://github.com/verda-cloud/sdk-python/blob/master/docs/source/examples/advanced_create_instance.md This Python snippet checks the user's balance and deploys either a high-capacity or a standard instance type based on cost. It requires environment variables for authentication and assumes specific instance type names. ```python import os from verda import VerdaClient from verda.exceptions import APIException # The instance types we want to deploy INSTANCE_TYPE_8V = '8V100.48V' INSTANCE_TYPE_4V = '4V100.20V' # Arbitrary duration for the example DURATION = 24 * 7 # one week # Get client secret from environment variable CLIENT_SECRET = os.environ['VERDA_CLIENT_SECRET'] CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi' # Replace with your client ID try: # Create client verda = VerdaClient(CLIENT_ID, CLIENT_SECRET) # Create new SSH key public_key = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI0qq2Qjt5GPi7DKdcnBHOkvk8xNsG9dA607tnWagOkHC test_key' ssh_key = verda.ssh_keys.create('my test key', public_key) # Get all SSH keys ssh_keys = verda.ssh_keys.get() ssh_keys_ids = list(map(lambda ssh_key: ssh_key.id, ssh_keys)) # Get our current balance balance = verda.balance.get() print(balance.amount) # Get instance types instance_types = verda.instance_types.get() # Deploy 8V instance if enough balance for a week, otherwise deploy a 4V for instance_details in instance_types: if instance_details.instance_type == INSTANCE_TYPE_8V: price_per_hour = instance_details.price_per_hour if price_per_hour * DURATION < balance.amount: # Deploy a new 8V instance instance = verda.instances.create(instance_type=INSTANCE_TYPE_8V, image='ubuntu-24.04-cuda-12.8-open-docker', ssh_key_ids=ssh_keys_ids, hostname='example', description='large instance', os_volume={ "name": "Large OS volume", "size": 95, }) else: # Deploy a new 4V instance instance = verda.instances.create(instance_type=INSTANCE_TYPE_4V, image='ubuntu-24.04-cuda-12.8-open-docker', ssh_key_ids=ssh_keys_ids, hostname='example', description='medium instance') except APIException as exception: print(exception) ``` -------------------------------- ### Create Instance with Advanced Retry Options Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md The instances.create() method now accepts keyword arguments for controlling retry behavior, including max_wait_time, initial_interval, max_interval, and backoff_coefficient. ```python # Example usage (assuming parameters are passed to instances.create()) ``` -------------------------------- ### Format Code with Ruff Source: https://github.com/verda-cloud/sdk-python/blob/master/README.md Format code according to style guidelines using Ruff. ```bash uv run ruff format ``` -------------------------------- ### Configure OS Volume for Spot Instance Discontinuation Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Set the `on_spot_discontinue` policy for an OS volume when creating a spot instance. This determines how the volume is handled when the instance is discontinued. ```python instance = verda_client.instances.create( hostname='test-instance', location=Locations.FIN_03, instance_type='CPU.4V.16G', description='test cpu instance', image='ubuntu-22.04', is_spot=True, ssh_key_ids=[ssh_key.id], os_volume=OSVolume( name='test-os-volume-spot', size=56, on_spot_discontinue='delete_permanently', ), ) ``` -------------------------------- ### Volume Deletion and Initialization Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Supports permanent deletion of volumes and initializing a Volume instance from a dictionary. Includes integration tests for permanent deletion. ```python # Example usage (assuming volume object and deletion/initialization methods) ``` -------------------------------- ### Manage Python Development Environment with uv Source: https://github.com/verda-cloud/sdk-python/blob/master/CHANGELOG.md Commands for removing old environments, synchronizing dependencies, and running Python scripts using uv. ```bash # remove old environment rm -rf datacrunch.egg-info/ .venv/ datacrunch_env/ # create new environment and install dependencies uv sync # run example uv run python examples/simple_create_instance.py ```