Koji Python Client

1.36.0 · active · verified Fri Apr 17

Koji is a powerful, distributed system for building and tracking RPM packages, primarily used within the Fedora and Red Hat ecosystems. The `koji` Python package provides the official client library, allowing programmatic interaction with a Koji Hub, including querying build information, submitting tasks, and managing users. It is actively maintained and currently at version 1.36.0, with releases typically tied to major Koji system updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates connecting to a public Koji Hub and querying its version. For anonymous access, no special configuration is needed. For tasks requiring authentication (e.g., submitting builds, modifying tags), Koji typically uses configuration files like `~/.koji/config` or environment variables for certificates.

import koji
import os

# Koji Hub URL. For authenticated access, Koji typically reads ~/.koji/config
# or uses certificate paths.
# We'll use a public read-only hub for this quickstart.
KOJI_HUB_URL = os.environ.get('KOJI_HUB_URL', 'https://koji.fedoraproject.org/kojihub')

try:
    session = koji.ClientSession(KOJI_HUB_URL)
    print(f"Connected to Koji Hub: {KOJI_HUB_URL}")

    # Get and print the Koji server version to confirm connectivity
    server_info = session.getKojiVersion()
    print(f"Koji server version: {server_info['version']} ({server_info['release']})")

    # Example: Get info for a specific build (if you know an NVR)
    # For a real scenario, you'd look up a valid NVR first.
    # print("\nTrying to find a specific build (e.g., 'kernel-5.18.11-200.fc36')")
    # try:
    #     build_info = session.getBuild('kernel-5.18.11-200.fc36')
    #     print(f"Found build: {build_info['nvr']} (ID: {build_info['build_id']})")
    # except Exception as e:
    #     print(f"Could not find build or an error occurred: {e}")

except koji.AuthError as e:
    print(f"Authentication Error: {e}")
    print("\nIf you intend to use authenticated access, ensure your Koji configuration (e.g., ~/.koji/config) is correct.")
except Exception as e:
    print(f"An error occurred during Koji interaction: {e}")

view raw JSON →