Typed synchronous and asynchronous clients for the Harbor API.
Maintained. Last release today, commits in 3 of the last 26 weeks. Weaker on commit activity.
pip install harbor-framework-clientREADME as published on PyPI with version 0.4.0.
Harbor API Python SDK
Typed synchronous and asynchronous clients for the Harbor API.
pip install harbor-framework-client
The distribution is named harbor-framework-client and the import package is harbor_client. The unrelated harbor-client project on PyPI is a different package. Python 3.12 or newer is required. Install the tus extra for resumable uploads: pip install "harbor-framework-client[tus]".
Quickstart
from harbor_client import HarborAPIClient
with HarborAPIClient(token="your-api-key") as client:
for job in client.jobs.list(state="running"):
print(job.id, job.name)
token takes a string or a callable that returns the current token. Each client owns one connection pool; use it as a context manager or call close().
Async
import asyncio
from harbor_client import AsyncHarborAPIClient
async def main() -> None:
async with AsyncHarborAPIClient(token="your-api-key") as client:
async for job in client.jobs.list():
print(job.id, job.name)
asyncio.run(main())
AsyncHarborAPIClient also accepts async_token, an async callable that returns the token. Call await client.aclose() when you do not use the context manager.
Pagination
List methods return pagers. Iterate a pager for items across all pages, or use iter_pages() for one page at a time:
pager = client.jobs.list(page_size="50")
for page in pager.iter_pages():
print(len(page))
Errors
HTTP errors raise harbor_client.core.ApiError or one of its subclasses exported from harbor_client, such as NotFoundError, UnauthorizedError and ConflictError. The error carries status_code and the parsed problem body; its message shows the problem's detail. Error messages never include request or response headers.
from harbor_client import NotFoundError
try:
client.jobs.get(job_id="3f6c2a1e-8b4d-4e2a-9c1f-5d7e8a9b0c12")
except NotFoundError as error:
print(error.status_code, error.body)