Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.
HsfPlugins

Harness Platform SDK

Install, configure, and use the Harness Platform SDK, a production-grade Python SDK for the Harness platform API.

The Harness Platform SDK is a production-grade Python SDK for the Harness platform API. It is built with Pydantic v2 and httpx, and it ships with a test suite. Typed wrappers cover Next-Gen (Core), Pipelines, Authorization, Infrastructure as Code, and Internal Developer Portal, so Python tools can call Harness without repeated Bash or curl scripts.

Version 1.0.0 is synchronous only. Async support is planned for a later release.


What you will learn from this topic

  • Install options: How to install the SDK from PyPI, Docker, or a local checkout.

  • Client setup: How HarnessClient takes an API key, account ID, and default org and project.

  • Resource coverage: Which platform domains and resources the typed wrappers include.

  • Errors and scope: How authentication failures, API errors, and missing scope are reported.


Before you begin

Confirm the following before you install the SDK:

  • Python 3.11 or later: The package is tested on Python 3.11, 3.12, and 3.14.

  • Harness API credentials: You need an API key and the account ID the client will call. Go to RBAC in Harness to confirm the key's role can call the resources you use.

  • Network access to Harness: The client calls https://app.harness.io unless you set another base URL.


Use the SDK

Install the package, create a client, and use the tables and examples below for modules, errors, scope, and tests.

Package notes

These constraints apply to the 1.0.0 release:

  • Python: 3.11 or later.

  • License: Business Source License 1.1 (BUSL-1.1).

  • Concurrency: Synchronous calls only. Async support is not in this version.

Install the SDK

Install from PyPI for local development. Use the image when you want a fixed runtime, or install from source when you are changing the SDK.

Create a client

Construct HarnessClient with an API key, account ID, and optional default org and project. Use the client as a context manager so the HTTP client closes when the block ends.

Core modules

These types are the entry points for configuration, calls, and failures:

Module
Description

HarnessClient

Main entry point for all API interactions. Handles HTTP methods with built-in retry (429, 503), scope resolution (account/org/project), URL template substitution, and pagination.

HarnessConfig

Configuration management: API key, account ID, base URL, timeout, retry settings, and SSL verification control.

Scope

Frozen Pydantic model representing request context. Requires account ID; org and project are optional.

PaginationStyle

Enum for pagination type: OFFSET (pageIndex/pageSize) or CURSOR (nextPageToken).

Exception hierarchy

HarnessSdkError (base), ScopeNotSetError (missing required scope fields), ApiError (non-2xx responses, with status/body/headers), AuthError (401/403 responses).

Resource APIs

Typed wrappers are grouped by platform domain:

Domain
Resources

Next-Gen (Core)

Organizations, Projects, Services, Service Overrides, Connectors, Secrets, Infrastructures, Variables, User Groups, Environments V2

Pipeline

Pipelines (v0), Input Sets (v0), Triggers (v0), Templates (v0)

Authorization

Roles, Resource Groups, Role Assignments

Infrastructure as Code

Workspaces, Workspace Approvals, Workspace States, Workspace Variables, Workspace Default Pipelines

Internal Developer Portal

Entities, Catalog Custom Properties, Scores

Design principles

The client follows six rules:

  1. Single entry point: All domain APIs are accessed through HarnessClient.

  2. Scope resolution: The client merges call-time scope with the default scope.

  3. Type safety: Request and response models are Pydantic v2 models with validation.

  4. Error handling: Failures raise explicit exception types with actionable messages.

  5. Retry logic: Transient failures retry with exponential backoff.

  6. No async: Calls are synchronous through httpx. Async support is deferred to a later version.

Configure the client

Pass keyword arguments for a short setup, or build a HarnessConfig when you need timeouts, retries, or a non-default base URL.

Handle API errors

Catch AuthError for 401 and 403 responses, and ApiError for other non-2xx responses. Call close() when you do not use the context manager.

Set request scope

Set the default org and project on the client, then replace that default later with set_default_scope. Account ID is required. Org and project are optional.

Scope is the frozen model the client uses for that context. Construct a client as shown above. You do not need to build a Scope yourself for the default path.

Run tests

From a source checkout, run the suite with mise or pytest:

CI enforces a coverage target of at least 85 percent.

Version and support

Release 1.0.0 is the current production version. Use these links for license terms, source, and issues:


Troubleshooting

Import fails after upgrading from harness-python-sdk

1.0.0 does not keep the old package name. Uninstall harness-python-sdk, run pip install harness-platform-sdk, and change imports to from harness_platform_sdk import ....

AuthError on the first API call

AuthError means the platform returned 401 or 403. Confirm api_key and account_id on the client, and confirm the key's role includes the resource you called. The status_code attribute on the exception is the HTTP status.

ScopeNotSetError before a request is sent

ScopeNotSetError means a required scope field is missing. Every client needs account_id. Set it in the HarnessClient constructor or on HarnessConfig. Org and project stay optional unless the resource you call requires them.

Calls fail on Python older than 3.11

The package requires Python 3.11 or later. Check python --version and recreate the virtual environment with a supported interpreter before you install again.


Next steps

You can install the SDK and call platform resources through HarnessClient.

Last updated

Was this helpful?