The OpenShift Python Wrapper provides a simple and intuitive interface for interacting with OpenShift and Kubernetes clusters. It standardizes resource CRUD operations and offers additional capabilities that simplify cluster management.
Requirements
The library requires Python 3.10 or higher .
Installation Methods
Install from PyPI (Recommended)
Install the latest stable version from PyPI using your preferred package manager: pip
uv (Recommended)
poetry
pipenv
pip install openshift-python-wrapper
uv is a fast Python package installer and is the recommended tool for managing dependencies.
Install from Source
For development or to use the latest features, install directly from the source repository: git clone https://github.com/RedHatQE/openshift-python-wrapper.git
cd openshift-python-wrapper
uv sync
To use the local installation in another project: uv pip install /path/to/openshift-python-wrapper
Verify Installation
Verify the installation by importing the library: from ocp_resources.resource import get_client
from ocp_resources.namespace import Namespace
print ( "OpenShift Python Wrapper installed successfully!" )
Dependencies
The library automatically installs the following key dependencies:
kubernetes (>=31.0.0) - Official Kubernetes Python client
timeout-sampler - Utilities for waiting and polling resources
python-simple-logger - Logging utilities
deepdiff - Deep comparison of resource states
jsonschema - Schema validation for resources
requests - HTTP library for API calls
Authentication Setup
The wrapper supports multiple authentication methods. Configure your cluster access using one of the following:
Using kubeconfig (Default)
The library automatically reads from your kubeconfig file: # Default location
export KUBECONFIG =~ /. kube / config
from ocp_resources.resource import get_client
# Uses default kubeconfig
client = get_client()
# Or specify a custom kubeconfig file
client = get_client( config_file = "/path/to/kubeconfig" )
# Use a specific context
client = get_client( context = "my-cluster-context" )
Authenticate using an API token: from ocp_resources.resource import get_client
client = get_client(
host = "https://api.cluster.example.com:6443" ,
token = "your-bearer-token-here" ,
verify_ssl = True
)
Using Username and Password
Authenticate with basic credentials (uses OAuth flow): from ocp_resources.resource import get_client
client = get_client(
host = "https://api.cluster.example.com:6443" ,
username = "your-username" ,
password = "your-password" ,
verify_ssl = True
)
Using Configuration Dictionary
Pass kubeconfig as a dictionary: from ocp_resources.resource import get_client
config_dict = {
"clusters" : [{
"name" : "my-cluster" ,
"cluster" : {
"server" : "https://api.cluster.example.com:6443" ,
"certificate-authority-data" : "..."
}
}],
"users" : [{
"name" : "my-user" ,
"user" : { "token" : "..." }
}],
"contexts" : [{
"name" : "my-context" ,
"context" : { "cluster" : "my-cluster" , "user" : "my-user" }
}],
"current-context" : "my-context"
}
client = get_client( config_dict = config_dict)
Environment Configuration
Logging
Control the logging level for the wrapper:
export OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL = "INFO"
# Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
Disable log data hashing in secure environments:
export OPENSHIFT_PYTHON_WRAPPER_HASH_LOG_DATA = "false"
Setting OPENSHIFT_PYTHON_WRAPPER_HASH_LOG_DATA="false" will expose sensitive information in logs. Only use this in secure environments.
Proxy Configuration
Route traffic through a proxy server:
export HTTPS_PROXY = "http://proxy.example.com:8080"
# or
export HTTP_PROXY = "http://proxy.example.com:8080"
The library automatically detects and uses the proxy configuration.
Additional Features
Fake Kubernetes Client
For testing without a real cluster, use the built-in fake client:
from ocp_resources.resource import get_client
# Get a fake client for testing
client = get_client( fake = True )
See the Fake Kubernetes Client documentation for details.
The library includes command-line utilities:
class-generator - Generate resource classes from OpenShift API schemas
openshift-mcp-server - MCP server for exposing OpenShift functionality
# Check available commands
class-generator --help
openshift-mcp-server --help
Next Steps
Quickstart Guide Get started with basic operations and examples
Core Concepts Learn about resources, clients, and patterns