Harness Python SDK

1.0.5 · active · verified Fri Apr 17

harness-python-sdk is the official Python SDK for programmatic interaction with Harness services. It provides a convenient client to automate tasks, manage resources, and integrate Harness functionality into other applications. The current version is 1.0.5, and it appears to have an infrequent release cadence, focusing on stability.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `HarnessClient` using API key and account ID, preferably loaded from environment variables for security. It then attempts to access a sub-service (PlatformService) to verify connection, catching potential initialization or API errors.

import os
from harness_python_sdk.client import HarnessClient

# Securely load credentials from environment variables
ACCOUNT_ID = os.environ.get('HARNESS_ACCOUNT_ID', 'your_account_id')
API_KEY = os.environ.get('HARNESS_API_KEY', 'your_api_key')

if not ACCOUNT_ID or not API_KEY:
    print("Please set HARNESS_ACCOUNT_ID and HARNESS_API_KEY environment variables or replace placeholders.")
else:
    try:
        # Initialize the Harness Client
        client = HarnessClient(account_id=ACCOUNT_ID, api_key=API_KEY)
        print(f"Harness Client initialized for Account ID: {ACCOUNT_ID}")

        # Example: Try to access a service (e.g., PlatformService)
        # This will raise an exception if credentials are bad or API is unreachable
        platform_service = client.platform
        # In a real scenario, you'd call a method on platform_service, e.g., list users
        print("Successfully accessed platform service. Connection appears valid.")

    except Exception as e:
        print(f"An error occurred during client initialization or API access: {e}")

view raw JSON →