Skip to main content

PyPI version Documentation Status build status coverage report Code style: black Code style: flake8 Code style: mypy

Kuber

kuber is Python library for the management of Kubernetes resources. It's ideal for collectively managing groups of resources throughout their lifecycle. Resource definitions can be created and managed entirely in Python code (the pure-Python approach), but kuber is most effective when used in a hybrid fashion that combines configuration files and Python code. kuber also integrates and maintains compatibility with the lower-level official Kubernetes Python client, while abstracting basic CRUD operations into higher level constructs more inline with the behaviors of tools like kubectl and helm.

Key Functionality

Here are some key things that kuber does well:

  • A flexible workflow for managing Kubernetes resource configuration in Python code.
  • The ability to load resources directly from YAML or JSON configuration files, modify them in code and then use them or save them back to YAML/JSON files.
  • Resource bundling for managing groups of resource configurations collectively.
  • CRUD operations exposed directly on the resource objects to reduce the overhead in managing low-level clients.
  • Convenience functions that simplify common operations, e.g. managing containers within pods from the root resource.
  • Very thorough type-hinting and object structure to support creating accurate resource configurations and catch errors before runtime.
  • All resources and sub-resources support used in with blocks as context managers to simplify making multiple changes to a sub-resource.
  • Simultaneous support for multiple Kubernetes API versions. Manage multiple Kubernetes API versions (e.g. while promoting new versions from development to production) without having to pin and switch Python environments.

Installation

kuber available for installation with pip:

$ pip install kuber

Quickstart

kuber can be used to manage individual resources or a group of resources collectively. kuber is also very flexible about how resources are created - either directly from Python or by loading and parsing YAML/JSON configuration files. The first example shows the multi-resource management path:

import kuber
from kuber.latest import apps_v1

# Create a bundle and load all resource definitions from the
# `app_configs` directory as well as the `app-secret.yaml`
# configuration file from the local `secrets` directory.
resource_bundle = (
    kuber.create_bundle()
    .add_directory("app_configs")
    .add_file("secrets/app-secret.yaml")
)

# Modify the metadata labels on all resources in the bundle.
for resource in resource_bundle.resources:
    resource.metadata.labels.update(environment="production")

# Update the replica count of the loaded deployment named
# "my-app" to the desired initial count.
d: apps_v1.Deployment = resource_bundle.get(
    name="my-app",
    kind="Deployment"
)
d.spec.replicas = 20

# Load the current `kubeconfig` cluster configuration into
# kuber for interaction with the cluster.
kuber.load_access_config()

# Turn this bundle script into a file that can be called from
# the command line to carry out CRUD operations on all the
# resources contained within it collectively. For example,
# to create the resources in this bundle, call this script
# file with a create argument.
resource_bundle.cli()

Or managing resources individually:

from kuber.latest import batch_v1

job = batch_v1.Job()

# Populate metadata using context manager syntax for brevity.
with job.metadata as md:
    md.name = "my-job"
    md.namespace = "jobs"
    md.labels.update(
        component="backend-tasks",
        environment="production"
    )

# Add a container to the job spec.
job.spec.append_container(
    name="main",
    image="my-registry.com/projects/my-job:1.0.1",
    image_pull_policy="Always",
    env=[batch_v1.EnvVar("ENVIRONMENT", "production")]
)

# Print the resulting YAML configuration for display. This
# could also be saved somewhere to use later as the
# configuration file to deploy to the cluster in cases
# like a multi-stage CI pipeline.
print(job.to_yaml())

Check out the kuber documentation for more details and examples.

Metadata

Release files for kuber 1.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kuber 1.17.0
File Size Uploaded Provenance
kuber-1.17.0.tar.gz 2.4 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kuber 1.17.0
File Interpreter ABI Platform
kuber-1.17.0-py3-none-any.whl Python 3 none any Details

Total release size: 5.0 MB

Release files / kuber-1.17.0.tar.gz

Download URL kuber-1.17.0.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
038b264e24248d12a862046bcecd3f5c698b02da5447b8837a5c3fdf0bef6379
BLAKE2b-256 checksum
How to use checksums
dccd42264ecff65d8eb1f7700e38fbf5e4cb8d5f6198be6b5a0efbcbafc23fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.1 Windows/10

Release files / kuber-1.17.0-py3-none-any.whl

Download URL kuber-1.17.0-py3-none-any.whl
Size 2.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
abe71ffda504310f4ec65ed96242e0c7fac8aa4879b24cb2b5cb474a3f255a5e
BLAKE2b-256 checksum
How to use checksums
b3a35f81c2cf5c4c128ca14edf17b78767435395a960254e9a3c0a78af01e17e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.1 Windows/10

Security for kuber 1.17.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.17.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page