SDK Python
SDK Python
Section intitulée « SDK Python »Le SDK Python utilise httpx pour les appels HTTP et supporte les opérations synchrones et asynchrones.
Installation
Section intitulée « Installation »pip install deploymeAuthentification
Section intitulée « Authentification »from deployme import DeploymeClient
# Via tokenclient = DeploymeClient(api_token="YOUR_API_TOKEN")
# Via variable d'environnement (DEPLOYME_API_TOKEN)client = DeploymeClient()Gestion des clusters
Section intitulée « Gestion des clusters »Créer un cluster
Section intitulée « Créer un cluster »cluster = client.clusters.create( name="production", control_planes=3, workers=5, node_size="large", phase="managed",)print(f"Cluster {cluster.name} — Status: {cluster.status}")Lister les clusters
Section intitulée « Lister les clusters »clusters = client.clusters.list()for cluster in clusters: print(f"{cluster.name} — {cluster.status} ({cluster.node_count} nodes)")Récupérer le kubeconfig
Section intitulée « Récupérer le kubeconfig »kubeconfig = client.clusters.get_kubeconfig("cluster-id")with open("kubeconfig.yaml", "w") as f: f.write(kubeconfig)Supprimer un cluster
Section intitulée « Supprimer un cluster »client.clusters.delete("cluster-id")Utilisation asynchrone
Section intitulée « Utilisation asynchrone »import asynciofrom 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())Gestion des erreurs
Section intitulée « Gestion des erreurs »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}")