kuber


Namekuber JSON
Version 1.17.0 PyPI version JSON
download
home_pagehttps://github.com/sernst/kuber
SummaryAccelerated Kubernetes configuration and package management with Python.
upload_time2023-03-20 22:04:26
maintainer
docs_urlNone
authorScott Ernst
requires_python>=3.8,<3.12
licenseMIT
keywords kubernetes
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            [![PyPI version](https://img.shields.io/pypi/v/kuber.svg)](https://pypi.python.org/pypi/kuber)
[![Documentation Status](https://readthedocs.org/projects/kuber/badge/?version=latest)](https://kuber.readthedocs.io/en/latest/?badge=latest)
[![build status](https://gitlab.com/swernst/kuber/badges/master/pipeline.svg)](https://gitlab.com/swernst/kuber/commits/master)
[![coverage report](https://gitlab.com/swernst/kuber/badges/master/coverage.svg)](https://gitlab.com/swernst/kuber/commits/master)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Code style: flake8](https://img.shields.io/badge/code%20style-flake8-white)](https://gitlab.com/pycqa/flake8)
[![Code style: mypy](https://img.shields.io/badge/code%20style-mypy-white)](http://mypy-lang.org/)

# 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](https://github.com/kubernetes-client/python),
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](https://pypi.org/project/pip/):

```bash
$ 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:

```python
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:

```python
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](https://kuber.readthedocs.io/en/latest/)
for more details and examples.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sernst/kuber",
    "name": "kuber",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<3.12",
    "maintainer_email": "",
    "keywords": "kubernetes",
    "author": "Scott Ernst",
    "author_email": "swernst@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/dc/cd/42264ecff65d8eb1f7700e38fbf5e4cb8d5f6198be6b5a0efbcbafc23fcd/kuber-1.17.0.tar.gz",
    "platform": null,
    "description": "[![PyPI version](https://img.shields.io/pypi/v/kuber.svg)](https://pypi.python.org/pypi/kuber)\n[![Documentation Status](https://readthedocs.org/projects/kuber/badge/?version=latest)](https://kuber.readthedocs.io/en/latest/?badge=latest)\n[![build status](https://gitlab.com/swernst/kuber/badges/master/pipeline.svg)](https://gitlab.com/swernst/kuber/commits/master)\n[![coverage report](https://gitlab.com/swernst/kuber/badges/master/coverage.svg)](https://gitlab.com/swernst/kuber/commits/master)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Code style: flake8](https://img.shields.io/badge/code%20style-flake8-white)](https://gitlab.com/pycqa/flake8)\n[![Code style: mypy](https://img.shields.io/badge/code%20style-mypy-white)](http://mypy-lang.org/)\n\n# Kuber\n\nkuber is Python library for the management of Kubernetes resources. It's\nideal for collectively managing groups of resources throughout their\nlifecycle. Resource definitions can be created and managed entirely in Python\ncode (the pure-Python approach), but kuber is most effective when used in a\nhybrid fashion that combines configuration files and Python code.\nkuber also integrates and maintains compatibility with the lower-level official\n[Kubernetes Python client](https://github.com/kubernetes-client/python),\nwhile abstracting basic CRUD operations into higher level constructs\nmore inline with the behaviors of tools like *kubectl* and *helm*.\n\n## Key Functionality\n\nHere are some key things that kuber does well:\n\n- A flexible workflow for managing Kubernetes resource configuration in Python\n  code.\n- The ability to load resources directly from YAML or JSON configuration files,\n  modify them in code and then use them or save them back to YAML/JSON files.\n- Resource bundling for managing groups of resource configurations collectively.\n- CRUD operations exposed directly on the resource objects to reduce the\n  overhead in managing low-level clients.\n- Convenience functions that simplify common operations, e.g. managing\n  containers within pods from the root resource.\n- Very thorough type-hinting and object structure to support creating accurate\n  resource configurations and catch errors before runtime.\n- All resources and sub-resources support used in `with` blocks as context\n  managers to simplify making multiple changes to a sub-resource.\n- Simultaneous support for multiple Kubernetes API versions. Manage multiple\n  Kubernetes API versions (e.g. while promoting new versions from development\n  to production) without having to pin and switch Python environments.\n\n## Installation\n\nkuber available for installation with [pip](https://pypi.org/project/pip/):\n\n```bash\n$ pip install kuber\n```\n \n## Quickstart\n\nkuber can be used to manage individual resources or a group of resources\ncollectively. kuber is also very flexible about how resources are created - \neither directly from Python or by loading and parsing YAML/JSON configuration\nfiles. The first example shows the multi-resource management path:\n\n```python\nimport kuber\nfrom kuber.latest import apps_v1\n\n# Create a bundle and load all resource definitions from the\n# `app_configs` directory as well as the `app-secret.yaml`\n# configuration file from the local `secrets` directory.\nresource_bundle = (\n    kuber.create_bundle()\n    .add_directory(\"app_configs\")\n    .add_file(\"secrets/app-secret.yaml\")\n)\n\n# Modify the metadata labels on all resources in the bundle.\nfor resource in resource_bundle.resources:\n    resource.metadata.labels.update(environment=\"production\")\n\n# Update the replica count of the loaded deployment named\n# \"my-app\" to the desired initial count.\nd: apps_v1.Deployment = resource_bundle.get(\n    name=\"my-app\",\n    kind=\"Deployment\"\n)\nd.spec.replicas = 20\n\n# Load the current `kubeconfig` cluster configuration into\n# kuber for interaction with the cluster.\nkuber.load_access_config()\n\n# Turn this bundle script into a file that can be called from\n# the command line to carry out CRUD operations on all the\n# resources contained within it collectively. For example,\n# to create the resources in this bundle, call this script\n# file with a create argument.\nresource_bundle.cli()\n```\n\nOr managing resources individually:\n\n```python\nfrom kuber.latest import batch_v1\n\njob = batch_v1.Job()\n\n# Populate metadata using context manager syntax for brevity.\nwith job.metadata as md:\n    md.name = \"my-job\"\n    md.namespace = \"jobs\"\n    md.labels.update(\n        component=\"backend-tasks\",\n        environment=\"production\"\n    )\n\n# Add a container to the job spec.\njob.spec.append_container(\n    name=\"main\",\n    image=\"my-registry.com/projects/my-job:1.0.1\",\n    image_pull_policy=\"Always\",\n    env=[batch_v1.EnvVar(\"ENVIRONMENT\", \"production\")]\n)\n\n# Print the resulting YAML configuration for display. This\n# could also be saved somewhere to use later as the\n# configuration file to deploy to the cluster in cases\n# like a multi-stage CI pipeline.\nprint(job.to_yaml())\n```\n\nCheck out the [kuber documentation](https://kuber.readthedocs.io/en/latest/)\nfor more details and examples.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Accelerated Kubernetes configuration and package management with Python.",
    "version": "1.17.0",
    "split_keywords": [
        "kubernetes"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b3a35f81c2cf5c4c128ca14edf17b78767435395a960254e9a3c0a78af01e17e",
                "md5": "3e7c5362c1f94a06b457ab32acfc459c",
                "sha256": "abe71ffda504310f4ec65ed96242e0c7fac8aa4879b24cb2b5cb474a3f255a5e"
            },
            "downloads": -1,
            "filename": "kuber-1.17.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e7c5362c1f94a06b457ab32acfc459c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<3.12",
            "size": 2649529,
            "upload_time": "2023-03-20T22:04:23",
            "upload_time_iso_8601": "2023-03-20T22:04:23.042208Z",
            "url": "https://files.pythonhosted.org/packages/b3/a3/5f81c2cf5c4c128ca14edf17b78767435395a960254e9a3c0a78af01e17e/kuber-1.17.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dccd42264ecff65d8eb1f7700e38fbf5e4cb8d5f6198be6b5a0efbcbafc23fcd",
                "md5": "956b189a3f6866873eaa0fdf16281b5a",
                "sha256": "038b264e24248d12a862046bcecd3f5c698b02da5447b8837a5c3fdf0bef6379"
            },
            "downloads": -1,
            "filename": "kuber-1.17.0.tar.gz",
            "has_sig": false,
            "md5_digest": "956b189a3f6866873eaa0fdf16281b5a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<3.12",
            "size": 2389177,
            "upload_time": "2023-03-20T22:04:26",
            "upload_time_iso_8601": "2023-03-20T22:04:26.575595Z",
            "url": "https://files.pythonhosted.org/packages/dc/cd/42264ecff65d8eb1f7700e38fbf5e4cb8d5f6198be6b5a0efbcbafc23fcd/kuber-1.17.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-20 22:04:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "sernst",
    "github_project": "kuber",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "lcname": "kuber"
}
        
Elapsed time: 0.04398s