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/awaitfor 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1b2245efa8f5031adad5ec4d0793674cf6fe1edfbc95f0cc9d2042eccb1ae1d
|
|
| MD5 |
c865c4c4c9e4a6f9333d3047ab2d03d3
|
|
| BLAKE2b-256 |
d9478f15311c3cc9f65f7bc4fc08dfa2f92d2b15e127a6fe88040184f9e9cf98
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19ba44e48f94ddc4f9cc3692c5a30f28e865a401f74d7d3dd93a8c60b9e5c786
|
|
| MD5 |
70e4a4e139842b6be5dada5f21627614
|
|
| BLAKE2b-256 |
62a6ec4aee14cd6f31a3d14a27002d9792ebad973926e365aee4b7d621406698
|