Google Cloud OS Config Client Library
The Google Cloud OS Config client library for Python provides tools to manage operating systems on virtual machine instances, offering functionalities for patch management, patch compliance reporting, and configuration management. Currently at version 1.24.0, it is actively maintained as part of the broader google-cloud-python monorepo, with frequent updates and releases.
Warnings
- breaking Python 3.9 is reaching or has reached End-of-Life (EOL) in late 2025/early 2026. While the PyPI `requires_python` currently indicates `>=3.9`, other Google Cloud client libraries are actively dropping official support for Python 3.9 as part of the monorepo's policy. Users on Python 3.9 should plan to upgrade to Python 3.10 or newer to ensure continued support and critical updates.
- gotcha Incorrect Google Cloud authentication setup. Common issues include missing or improperly configured `GOOGLE_APPLICATION_CREDENTIALS` environment variable, or the service account/user lacking necessary IAM permissions (e.g., `osconfig.patchJobs.list`).
- gotcha Misconfigured resource paths for API calls. Resource names for Google Cloud APIs follow specific patterns (e.g., `projects/PROJECT_ID`, `projects/PROJECT_ID/locations/LOCATION_ID`). Incorrect formatting will result in `NotFound` or `InvalidArgument` errors.
Install
-
pip install google-cloud-os-config
Imports
- OsConfigServiceClient
from google.cloud import osconfig_v1
- OsConfigServiceAsyncClient
from google.cloud import osconfig_v1
Quickstart
import os
from google.cloud import osconfig_v1
def list_patch_jobs():
# Set your Google Cloud Project ID as an environment variable or replace 'your-project-id'
project_id = os.environ.get('GCP_PROJECT_ID', 'your-project-id')
if project_id == 'your-project-id':
print("Please set the 'GCP_PROJECT_ID' environment variable or replace 'your-project-id'.")
return
client = osconfig_v1.OsConfigServiceClient()
parent_path = f"projects/{project_id}"
request = osconfig_v1.ListPatchJobsRequest(
parent=parent_path,
)
try:
page_result = client.list_patch_jobs(request=request)
print(f"Patch jobs for project {project_id}:")
for response in page_result:
print(f" - {response.name} (State: {response.state.name})")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure the OS Config API is enabled for your project and your credentials are set up correctly.")
if __name__ == "__main__":
list_patch_jobs()