Skip to main content

A transparent, lightweight Kubernetes manifest generator

Reason this release was yanked:

Old and deprecated.

Project description

k8smith

CI PyPI version Python 3.11+ License: GPL v3

A transparent, lightweight Kubernetes manifest generator.

Philosophy

  • Transparency over abstraction — Generated YAML is predictable; no hidden defaults
  • Composition over inheritance — Build complex resources from simple pieces
  • Type safety at the boundary — Validate inputs with Pydantic, output plain dicts
  • Cloud-agnostic core — Vanilla K8s resources work anywhere; cloud extensions are optional

Installation

pip install k8smith
# or
uv add k8smith

Quick Start

import k8smith as kk

# Create a deployment
from k8smith import (
    DeploymentSpec,
    Container,
    PodSpec,
    PodTemplateSpec,
    ResourceRequirements,
    ResourceQuantity,
    build_deployment,
    Manifest,
)

spec = DeploymentSpec(
    name="web",
    namespace="production",
    replicas=3,
    template=PodTemplateSpec(
        spec=PodSpec(
            containers=[
                Container(
                    name="web",
                    image="nginx:1.25",
                    resources=ResourceRequirements(
                        requests=ResourceQuantity(cpu="100m", memory="128Mi"),
                        limits=ResourceQuantity(memory="256Mi"),
                    ),
                )
            ]
        )
    ),
)

deployment = build_deployment(spec)

# Collect resources into a manifest
manifest = Manifest()
manifest.add(deployment)
print(manifest.to_yaml())

GPU Support (no workarounds needed!)

from k8smith import (
    Container,
    ResourceRequirements,
    ResourceQuantity,
)

container = Container(
    name="ml-worker",
    image="ml-training:v1",
    resources=ResourceRequirements(
        requests=ResourceQuantity(memory="4Gi", cpu="1"),
        limits=ResourceQuantity(
            memory="8Gi",
            extended={"nvidia.com/gpu": "1"},  # Just works!
        ),
    ),
)

GKE Extensions

from k8smith.gke import (
    GatewaySpec,
    HTTPRouteSpec,
    build_gateway,
    build_httproute,
)

gateway = build_gateway(GatewaySpec(
    name="main-gateway",
    namespace="gateway",
    gateway_class_name="gke-l7-global-external-managed",
    listeners=[{
        "name": "https",
        "port": 443,
        "protocol": "HTTPS",
    }],
))

Core Resources

Resource Builder
Deployment build_deployment(DeploymentSpec)
Service build_service(ServiceSpec)
StatefulSet build_statefulset(StatefulSetSpec)
DaemonSet build_daemonset(DaemonSetSpec)
CronJob build_cronjob(CronJobSpec)
ConfigMap build_configmap(ConfigMapSpec)
Secret build_secret(SecretSpec)
HPA build_hpa(HPASpec)
PDB build_pdb(PDBSpec)
ServiceAccount build_serviceaccount(ServiceAccountSpec)
Namespace build_namespace(NamespaceSpec)
Role build_role(RoleSpec)
ClusterRole build_clusterrole(ClusterRoleSpec)
RoleBinding build_rolebinding(RoleBindingSpec)
ClusterRoleBinding build_clusterrolebinding(ClusterRoleBindingSpec)

GKE Resources

Resource Builder
Gateway build_gateway(GatewaySpec)
HTTPRoute build_httproute(HTTPRouteSpec)
HealthCheckPolicy build_healthcheckpolicy(HealthCheckPolicySpec)
GCPBackendPolicy build_gcp_backend_policy(GCPBackendPolicySpec)
PodMonitoring build_pod_monitoring(PodMonitoringSpec)
ClusterPodMonitoring build_cluster_pod_monitoring(ClusterPodMonitoringSpec)

Why not cdk8s?

k8smith was created to replace cdk8s after encountering these issues:

cdk8s Problem k8smith Solution
Size.gibibytes(6) outputs 6144Mi Strings stay as strings: "6Gi"
Can't add nvidia.com/gpu via resources Built into ResourceQuantity.extended
Adds hostNetwork: false when not set Only outputs what you specify
Requires label cleanup post-processing No generated labels
JSII/Node.js dependency Pure Python

License

GPL-3.0 - See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

k8smith-0.1.1.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k8smith-0.1.1-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

File details

Details for the file k8smith-0.1.1.tar.gz.

File metadata

  • Download URL: k8smith-0.1.1.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for k8smith-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e56d306ec38441516ed8bbc089d38e2eb8f7c99e5113b2e0f5f0378eb67ce5e8
MD5 90b44fcb842c8821902bf209a248191e
BLAKE2b-256 f71f94dbc05eb48278a96288545a993f8abcd710b6be67796d94acbe1cdfc3cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for k8smith-0.1.1.tar.gz:

Publisher: release.yml on eliminyro/k8smith

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file k8smith-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: k8smith-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 42.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for k8smith-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68258a23572f9e0a565b9a55b2b682c0d1b4028f65bd472f4c20b2cca881ce37
MD5 f00711cdd2c2f65fff8ed215e0ce5a62
BLAKE2b-256 17d8839071f747cc468784bce5ea11dad5fa6ea7db0958840c3fe2612b5194a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for k8smith-0.1.1-py3-none-any.whl:

Publisher: release.yml on eliminyro/k8smith

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page