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
pip install pykustomize
The wheel bundles the Kustomize Go library for Linux x86_64; no kustomize binary is needed.
📖 Documentation
Full documentation, including the generated Python and Go shim reference, is at
https://docs.vantagecompute.ai/developer/pykustomize/ (sources in docusaurus/).
🚀 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, uv, just and Docker.
git clone https://github.com/vantagecompute/pykustomize.git
cd pykustomize
just env # create the virtual environment
just build-lib # build the native library in Docker
just check # lint, typecheck, build the library and run the tests
Run just to list every recipe. See the
development guide and
release process.
🏗️ 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
Metadata
Release files for pykustomize 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pykustomize-0.1.4.tar.gz | 12.5 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pykustomize-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.5 MB
Release files / pykustomize-0.1.4.tar.gz
| Download URL | pykustomize-0.1.4.tar.gz |
|---|---|
| Size | 12.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f9a468368faff3f3bd06c013f806c63b2b6cc1f88853f9bb5a410b069240eca
|
|
BLAKE2b-256 checksum How to use checksums |
0dcba94cda8e6101ac3df9379fcaa508a31d1d859b32f21bb72276bb16006497
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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}
|
Release files / pykustomize-0.1.4-py3-none-any.whl
| Download URL | pykustomize-0.1.4-py3-none-any.whl |
|---|---|
| Size | 25.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8da6be12fb35b56158d2f9043a67d39c1ce84eae9c8f344c7ed934709192467
|
|
BLAKE2b-256 checksum How to use checksums |
007cdbb190d6b383a4b6172d0f76aefaa48e02e9bfd33016e9ffb1e06d670957
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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}
|