Skip to main content

Python bindings for Kustomize - Kubernetes configuration customization

Project description

pykustomize

Python bindings for Kustomize - Kubernetes configuration customization.

pykustomize provides a complete Python wrapper for the Kustomize Go API, enabling you to build and customize Kubernetes configurations directly from Python. Following the architecture pattern of helm-sdkpy, it creates a self-contained package with no system dependencies.

โœจ Features

  • ๐Ÿš€ Async-first API - All operations use Python's async/await for non-blocking execution
  • ๐Ÿ“ฆ Self-contained - Bundles the Go library, no external kustomize binary needed
  • ๐Ÿ”’ Type-safe - Full type hints for IDE support and static analysis
  • ๐ŸŽฏ Simple API - Easy-to-use interface mirroring kustomize functionality
  • โšก Fast - Native Go performance through FFI

๐Ÿ“ฆ Installation

# Build the library first
just build-lib

# Install the package
pip install .

# Or install in development mode
pip install -e .

๐Ÿš€ Quick Start

import asyncio
from pykustomize import build, build_json, BuildOptions, LoadRestrictions

async def main():
    # Simple build - returns YAML
    result = await build("/path/to/kustomization")
    print(result.yaml)
    
    # Build with options
    options = BuildOptions(
        load_restrictions=LoadRestrictions.NONE,
        add_managedby_label=True,
    )
    result = await build("/path/to/overlay", options)
    
    # Build to JSON for programmatic access
    result_json = await build_json("/path/to/kustomization")
    for resource in result_json.resources:
        print(f"{resource['kind']}: {resource['metadata']['name']}")

asyncio.run(main())

๐Ÿ“š API Reference

Kustomizer

The main class for performing kustomize operations.

from pykustomize import Kustomizer, BuildOptions

kustomizer = Kustomizer()

# Build and get YAML
result = await kustomizer.build("/path/to/kustomization")
print(result.yaml)

# Build and get JSON
result = await kustomizer.build_json("/path/to/kustomization")
for resource in result.resources:
    print(resource)

# Get available plugins
plugins = await kustomizer.get_builtin_plugins()
print(plugins)

BuildOptions

Configure how kustomize processes the kustomization.

from pykustomize import BuildOptions, LoadRestrictions, ReorderOption

options = BuildOptions(
    # Control file loading (ROOT_ONLY is secure default)
    load_restrictions=LoadRestrictions.ROOT_ONLY,
    
    # Control output ordering
    reorder=ReorderOption.LEGACY,
    
    # Add managed-by label
    add_managedby_label=True,
    
    # Enable plugins
    enable_plugins=False,
    
    # Enable Helm chart inflation
    enable_helm=False,
    helm_command="/usr/local/bin/helm",
)

LoadRestrictions

Controls what files can be loaded during kustomization.

Value Description
ROOT_ONLY Only allow loading files from within the kustomization root (secure default)
NONE Allow loading files from anywhere (less secure, but more flexible)

ReorderOption

Controls the order of resources in the output.

Value Description
UNSPECIFIED Let kustomize select the appropriate default
LEGACY Use a fixed order for backwards compatibility
NONE Respect the depth-first resource input order

Convenience Functions

For simple use cases, use the module-level functions:

from pykustomize import build, build_json

# Build to YAML
result = await build("/path/to/kustomization")

# Build to JSON
result = await build_json("/path/to/kustomization")

๐Ÿ› ๏ธ Development

Prerequisites

  • Python 3.14+
  • Go 1.22+
  • Docker (for building the native library)
  • just (recommended)

Setup

# Clone the repository
git clone https://github.com/vantagecompute/pykustomize.git
cd pykustomize

# Install Python dependencies
uv sync

# Build the native library (using Docker)
just build-lib

# Or build locally if you have Go installed
just build-lib-local

# Run tests
just test

Available Commands

just                # List all commands
just build-lib      # Build native library using Docker
just build-lib-local # Build native library locally
just test           # Run tests
just lint           # Check code style
just typecheck      # Run type checking
just fmt            # Format code
just clean          # Clean build artifacts

๐Ÿ—๏ธ Architecture

pykustomize follows a three-layer architecture:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Python Application              โ”‚
โ”‚  (async/await, type hints)          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Python Layer (pykustomize)      โ”‚
โ”‚  - Kustomizer class                 โ”‚
โ”‚  - BuildOptions configuration       โ”‚
โ”‚  - Exception hierarchy              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚ asyncio.to_thread()
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     FFI Layer (CFFI)                โ”‚
โ”‚  - C function bindings              โ”‚
โ”‚  - Type marshalling                 โ”‚
โ”‚  - Error handling                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Go Shim Layer (CGO)             โ”‚
โ”‚  - Wraps kustomize/api/krusty       โ”‚
โ”‚  - Thread-safe with mutex           โ”‚
โ”‚  - JSON serialization               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Kustomize Go Library            โ”‚
โ”‚  sigs.k8s.io/kustomize/api          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Examples

See the examples/ directory for more usage examples.

๐Ÿ“ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Copyright 2025 Vantage Compute

๐Ÿค Contributing

Contributions welcome! Please ensure:

  • Code follows existing style (ruff formatting)
  • Tests pass and coverage is maintained
  • Type hints are included
  • Documentation is updated

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

pykustomize-0.1.1.tar.gz (12.7 MB view details)

Uploaded Source

Built Distribution

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

pykustomize-0.1.1-py3-none-any.whl (25.4 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pykustomize-0.1.1.tar.gz
  • Upload date:
  • Size: 12.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pykustomize-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c1b2245efa8f5031adad5ec4d0793674cf6fe1edfbc95f0cc9d2042eccb1ae1d
MD5 c865c4c4c9e4a6f9333d3047ab2d03d3
BLAKE2b-256 d9478f15311c3cc9f65f7bc4fc08dfa2f92d2b15e127a6fe88040184f9e9cf98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykustomize-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pykustomize-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 19ba44e48f94ddc4f9cc3692c5a30f28e865a401f74d7d3dd93a8c60b9e5c786
MD5 70e4a4e139842b6be5dada5f21627614
BLAKE2b-256 62a6ec4aee14cd6f31a3d14a27002d9792ebad973926e365aee4b7d621406698

See more details on using hashes here.

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