{"id":9805,"library":"harness-python-sdk","title":"Harness Python SDK","description":"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.","status":"active","version":"1.0.5","language":"en","source_language":"en","source_url":"https://github.com/ljw4010/harness_python_SDK","tags":["Harness","SDK","API client","CI/CD","DevOps"],"install":[{"cmd":"pip install harness-python-sdk","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The `HarnessClient` class is located within the `client` submodule, not directly at the top level of the package.","wrong":"from harness_python_sdk import HarnessClient","symbol":"HarnessClient","correct":"from harness_python_sdk.client import HarnessClient"},{"note":"Service classes are nested within the `services` subpackage, organized by specific Harness areas like `platform`.","wrong":"from harness_python_sdk import PlatformService","symbol":"PlatformService","correct":"from harness_python_sdk.services.platform import PlatformService"}],"quickstart":{"code":"import os\nfrom harness_python_sdk.client import HarnessClient\n\n# Securely load credentials from environment variables\nACCOUNT_ID = os.environ.get('HARNESS_ACCOUNT_ID', 'your_account_id')\nAPI_KEY = os.environ.get('HARNESS_API_KEY', 'your_api_key')\n\nif not ACCOUNT_ID or not API_KEY:\n    print(\"Please set HARNESS_ACCOUNT_ID and HARNESS_API_KEY environment variables or replace placeholders.\")\nelse:\n    try:\n        # Initialize the Harness Client\n        client = HarnessClient(account_id=ACCOUNT_ID, api_key=API_KEY)\n        print(f\"Harness Client initialized for Account ID: {ACCOUNT_ID}\")\n\n        # Example: Try to access a service (e.g., PlatformService)\n        # This will raise an exception if credentials are bad or API is unreachable\n        platform_service = client.platform\n        # In a real scenario, you'd call a method on platform_service, e.g., list users\n        print(\"Successfully accessed platform service. Connection appears valid.\")\n\n    except Exception as e:\n        print(f\"An error occurred during client initialization or API access: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Use environment variables (`os.environ.get`), a secrets management system (e.g., Vault, AWS Secrets Manager), or a configuration file that is not committed to version control.","message":"Always handle Harness API Key and Account ID securely. Do not hardcode them directly in your source code, especially in production environments.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you import from the correct submodule, e.g., `from harness_python_sdk.client import HarnessClient` and `from harness_python_sdk.services.platform import PlatformService`.","message":"The `HarnessClient` and other service objects (e.g., `PlatformService`) are nested within submodules. Incorrect import paths are a common source of `AttributeError` or `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Wrap your API calls in `try...except harness_python_sdk.exceptions.APIError as e:` blocks to gracefully handle and inspect API-returned error messages and codes.","message":"API calls can fail due to network issues, invalid input, or server errors. The SDK raises `harness_python_sdk.exceptions.APIError` for most API-specific errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install harness-python-sdk`","cause":"The `harness-python-sdk` package has not been installed or is not accessible in your current Python environment.","error":"ModuleNotFoundError: No module named 'harness_python_sdk'"},{"fix":"Correct the import statement to `from harness_python_sdk.client import HarnessClient`.","cause":"You are trying to import `HarnessClient` directly from the root `harness_python_sdk` package, but it resides in a submodule.","error":"AttributeError: module 'harness_python_sdk' has no attribute 'HarnessClient'"},{"fix":"Double-check your `HARNESS_ACCOUNT_ID` and `HARNESS_API_KEY` credentials. Ensure they are valid and have appropriate access rights in Harness.","cause":"The API Key or Account ID provided to the `HarnessClient` are incorrect, expired, or lack the necessary permissions for the requested operation.","error":"harness_python_sdk.exceptions.APIError: {'code': '401', 'message': 'Unauthorized', 'detail': ...}"}]}