Aller au contenu

SDK Python

Le SDK Python utilise httpx pour les appels HTTP et supporte les opérations synchrones et asynchrones.

Fenêtre de terminal
pip install deployme
from deployme import DeploymeClient
# Via token
client = DeploymeClient(api_token="YOUR_API_TOKEN")
# Via variable d'environnement (DEPLOYME_API_TOKEN)
client = DeploymeClient()
cluster = client.clusters.create(
name="production",
control_planes=3,
workers=5,
node_size="large",
phase="managed",
)
print(f"Cluster {cluster.name} — Status: {cluster.status}")
clusters = client.clusters.list()
for cluster in clusters:
print(f"{cluster.name}{cluster.status} ({cluster.node_count} nodes)")
kubeconfig = client.clusters.get_kubeconfig("cluster-id")
with open("kubeconfig.yaml", "w") as f:
f.write(kubeconfig)
client.clusters.delete("cluster-id")
import asyncio
from deployme import AsyncDeploymeClient
async def main():
client = AsyncDeploymeClient(api_token="YOUR_API_TOKEN")
cluster = await client.clusters.create(
name="async-cluster",
control_planes=1,
workers=2,
node_size="medium",
)
print(f"Cluster {cluster.name} créé !")
asyncio.run(main())
from deployme.exceptions import DeploymeAPIError, DeploymeNotFoundError
try:
cluster = client.clusters.get("invalid-id")
except DeploymeNotFoundError:
print("Cluster non trouvé")
except DeploymeAPIError as e:
print(f"Erreur API {e.status_code}: {e.message}")