Cloudcoil
Modern async-first Kubernetes client for Python with Pydantic models - bringing cloud-native operations and K8s development to life with elegant Pythonic APIs
Install / Use
/learn @cloudcoil/CloudcoilREADME
cloudcoil
🚀 Cloud native operations made beautifully simple with Python
Modern, async-first Kubernetes client with elegant Pythonic syntax and full type safety
🤝 Support the Project
If you find Cloudcoil useful, please consider giving it a star on GitHub! Your support helps the project grow and encourages continued development.
✨ Features
- 🔥 Elegant, Pythonic API - Feels natural to Python developers including fluent and context manager style resource builders
- ⚡ Async First - Native async/await support for high performance
- 🛡️ Type Safe - Full mypy support and runtime validation
- 🧪 Testing Ready - Built-in pytest fixtures for K8s integration tests
- 📦 Zero Config - Works with your existing kubeconfig
- 🪶 Minimal Dependencies - Only requires httpx, pydantic, and pyyaml
🔧 Installation
[!NOTE] For versioning information and compatibility, see the Versioning Guide.
Using uv (recommended):
# Install with Kubernetes support
uv add cloudcoil[kubernetes]
# Install with specific Kubernetes version compatibility
uv add cloudcoil[kubernetes-1-29]
uv add cloudcoil[kubernetes-1-30]
uv add cloudcoil[kubernetes-1-31]
uv add cloudcoil[kubernetes-1-32]
Using pip:
pip install cloudcoil[kubernetes]
🔌 Integrations
Discover more Cloudcoil model integrations for popular Kubernetes operators and CRDs at cloudcoil-models on GitHub.
Current first-class integrations include:
| Name | Github | PyPI | | ------- | ------- | ------- | | cert-manager | models-cert-manager | cloudcoil.models.cert_manager | | fluxcd | models-fluxcd | cloudcoil.models.fluxcd | | istio | models-istio | cloudcoil.models.istio | | keda | models-keda | cloudcoil.models.keda | | knative-serving | models-knative-serving | cloudcoil.models.knative_serving | | knative-eventing | models-knative-eventing | cloudcoil.models.knative_eventing | | kpack | models-kpack | cloudcoil.models.kpack | | kyverno | models-kyverno | cloudcoil.models.kyverno | | prometheus-operator | models-prometheus-operator | cloudcoil.models.prometheus_operator | | sealed-secrets | models-sealed-secrets | cloudcoil.models.sealed_secrets | | velero | models-velero | cloudcoil.models.velero |
You can install these integrations using
uv add cloudcoil[kyverno]
# You can also install multiple dependencies at once
uv add cloudcoil[cert-manager,fluxcd,kyverno]
# You can also install all available models in cloudcoil using
uv add cloudcoil[all-models]
Missing an integration you need? Open a model request to suggest a new integration!
💡 Examples
Reading Resources
from cloudcoil.client import Config
import cloudcoil.models.kubernetes as k8s
# Get a resource - as simple as that!
service = k8s.core.v1.Service.get("kubernetes")
# List resources with elegant pagination
for pod in k8s.core.v1.Pod.list(namespace="default"):
print(f"Found pod: {pod.metadata.name}")
# Async support out of the box
async for pod in await k8s.core.v1.Pod.async_list():
print(f"Found pod: {pod.metadata.name}")
Building resources
Using Models
from cloudcoil import apimachinery
import cloudcoil.models.kubernetes.core.v1 as k8score
import cloudcoil.models.kubernetes.apps.v1 as k8sapps
# Create a Deployment
deployment = k8sapps.Deployment(
metadata=apimachinery.ObjectMeta(name="nginx"),
spec=k8sapps.DeploymentSpec(
replicas=3,
selector=apimachinery.LabelSelector(
match_labels={"app": "nginx"}
),
template=k8score.PodTemplateSpec(
metadata=apimachinery.ObjectMeta(
labels={"app": "nginx"}
),
spec=k8score.PodSpec(
containers=[
k8score.Container(
name="nginx",
image="nginx:latest",
ports=[k8score.ContainerPort(container_port=80)]
)
]
)
)
)
).create()
# Create a Service
service = k8score.Service(
metadata=apimachinery.ObjectMeta(name="nginx"),
spec=k8score.ServiceSpec(
selector={"app": "nginx"},
ports=[k8score.ServicePort(port=80, target_port=80)]
)
).create()
# List Deployments
for deploy in k8sapps.Deployment.list():
print(f"Found deployment: {deploy.metadata.name}")
# Update a Deployment
deployment.spec.replicas = 5
deployment.save()
# Delete resources
k8score.Service.delete("nginx")
k8sapps.Deployment.delete("nginx")
Using the Fluent Builder API
Cloudcoil provides a powerful fluent builder API for Kubernetes resources with full IDE support and rich autocomplete capabilities:
from cloudcoil.models.kubernetes.apps.v1 import Deployment
from cloudcoil.models.kubernetes.core.v1 import Service
# Create a Deployment using the fluent builder
# The fluent style is great for one-liners and simple configurations
nginx_deployment = (
Deployment.builder()
# Metadata can be configured in a single chain for simple objects
.metadata(lambda metadata: metadata
.name("nginx")
.namespace("default")
)
# Complex nested structures can be built using nested lambda functions
.spec(lambda deployment_spec: deployment_spec
.replicas(3)
# Each level of nesting gets its own lambda for clarity
.selector(lambda label_selector: label_selector
.match_labels({"app": "nginx"})
)
.template(lambda pod_template: pod_template
.metadata(lambda pod_metadata: pod_metadata
.labels({"app": "nginx"})
)
.spec(lambda pod_spec: pod_spec
# Lists can be built using array literals with lambda items
.containers([
lambda container: container
.name("nginx")
.image("nginx:latest")
# Nested collections can use the add() helper
.ports(lambda port_list: port_list.add(
lambda port: port.container_port(80)
))
])
)
)
)
.build()
)
# Create a Service using the builder
service = (
Service.builder()
.metadata(lambda m: m
.name("nginx")
.namespace("default")
)
.spec(lambda s: s
.selector({"app": "nginx"})
.ports(lambda ports: ports.add(lambda p: p.container_port(80)))
)
.build()
)
The fluent builder provides:
- ✨ Full IDE support with detailed type information
- 🔍 Rich autocomplete for all fields and nested objects
- ⚡ Compile-time validation of your configuration
- 🎯 Clear and chainable API that guides you through resource creation
Using the Context Manager Builder API
For complex nested resources, Cloudcoil also provides a context manager-based builder pattern that can make the structure more clear:
from cloudcoil.models.kubernetes.apps.v1 import Deployment
from cloudcoil.models.kubernetes.core.v1 import Service
# Create a deployment using context managers
# Context managers are ideal for deeply nested structures
with Deployment.new() as nginx_deployment:
# Each context creates a clear visual scope
with nginx_deployment.metadata() as deployment_metadata:
deployment_metadata.name("nginx")
deployment_metadata.namespace("default")
with nginx_deployment.spec() as deployment_spec:
# Simple fields can be set directly
