Registry / devops / openshift-client

openshift-client

JSON →
library2.0.5pypypi✓ verified 79d ago

The `openshift-client` library provides a Pythonic interface for interacting with OpenShift clusters, built on top of the official Kubernetes Python client. It simplifies common OpenShift operations like managing projects, applications, and resources. The current version is 2.0.5, and it has an active development cadence with parallel maintenance of 1.x and 2.x branches, though 2.x is the primary focus for new features.

pip install openshift-client
INSTALL
IMPORT
SIG · OPENSHIFT-CLIENT
O
openshift-client
devopspythonv2.0.5
Install
2.2s avg
Import
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 21.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.2s · import 0.000s · 23MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

APIObject
from openshift_client import APIObject
from openshift_client import OC
Context
from openshift_client import Context
from openshift_client import OC
Selector
from openshift_client import Selector
from openshift_client import OC

This quickstart demonstrates how to initialize the `OC` client, switch to a specific OpenShift project (namespace), and list pods within that project. It assumes a `kubeconfig` file is available in the default location or specified via `KUBECONFIG_PATH` environment variable. It also shows how to retrieve the current project name and handle potential errors.

import os from openshift.client import OC # Instantiate the OC client. It automatically uses your default kubeconfig context. # Or specify a kubeconfig path: # oc_client = OC(kubeconfig=os.environ.get('KUBECONFIG_PATH', '~/.kube/config')) oc_client = OC() # Change to a specific project (namespace) project_name = os.environ.get('OPENSHIFT_PROJECT', 'default') oc_client.project(project_name) print(f"Current project: {oc_client.get_project_name()}") # List all pods in the current project try: pods = oc_client.selector('pods').objects() if pods: print(f"Found {len(pods)} pods in project '{project_name}':") for pod in pods: print(f" - {pod.metadata.name} (Status: {pod.status.phase})") else: print(f"No pods found in project '{project_name}'.") except Exception as e: print(f"Error listing pods: {e}") # Example: Get a specific resource (if it exists) # try: # deployment = oc_client.get('deployment', 'my-app-deployment') # print(f"Found deployment: {deployment.metadata.name}") # except Exception as e: # print(f"Deployment not found or error: {e}")
Debug
Known issues
breakingPython 2 support has been officially deprecated starting with versions 2.0.5 and 1.0.24. Future releases will drop Python 2 compatibility entirely.
fix
Migrate your environment and code to Python 3. This library now requires Python >=3.0.
affects: >=2.0.5, >=1.0.24
gotchaStarting with versions 2.0.2 and 1.0.22, the library internally uses timezone-aware datetime objects instead of timezone-naive `datetime.utcnow()`. This can lead to `TypeError: can't compare offset-naive and offset-aware datetimes` if your application code mixes naive and aware datetimes when interacting with API objects or their properties.
fix
Ensure all datetime operations and comparisons in your code are consistently using timezone-aware datetime objects (e.g., using `pytz` or `zoneinfo` modules). Convert naive datetimes to aware ones before use, typically UTC or the timezone of your cluster.
affects: >=2.0.2, >=1.0.22
gotchaThe `OC` client defaults to using the currently active context in your `kubeconfig` file. If you need to interact with a specific context or a different `kubeconfig` file, you must explicitly specify it.
fix
To use a specific context, instantiate with `OC.from_context('my-context-name')`. To use a different kubeconfig file, pass the path: `OC(kubeconfig='/path/to/my/kubeconfig')`.
affects: All versions
Upgrade
Version history
2.0.5latest on PyPI · released Dec 5, 2024
Audit
Dependencies
kubernetesrequiredCore API interaction with Kubernetes/OpenShift clusters.
PyYAMLrequiredUsed for parsing kubeconfig files and other YAML configurations.
requestsrequiredHTTP client for API communication.
urllib3requiredHTTP client library, dependency of requests.
Agent activity
19 hits · last 30 days
node
18
Amazon
1
Resources
openshift-client — pip install openshift-client · libregistry