> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-fr/prise-en-main/python-quickstart.md).

# Démarrage rapide SDK Python

{% hint style="success" %}
**Ce que vous allez construire :** En 5 minutes, vous rechercherez sur le marché des GPU, louerez un serveur et vous connecterez via SSH — le tout depuis du code ou la CLI.
{% endhint %}

## Prérequis

* **Python 3.9+** installé
* **Compte Clore.ai** — [inscrivez-vous ici](https://clore.ai)
* **Clé API** — obtenez-la depuis votre [tableau de bord Clore.ai](https://clore.ai)
* **Fonds** — minimum \~5 $ en BTC, CLORE, USDT ou USDC

***

## Étape 1 : Installer le SDK

```bash
pip install clore-ai
```

Vérifier l'installation :

```bash
clore --version
```

***

## Étape 2 : Configurez votre clé API

**Option A : Variable d'environnement (recommandé)**

```bash
export CLORE_API_KEY=your_api_key_here
```

**Option B : Configuration CLI (enregistrée dans `~/.clore/config.json`)**

```bash
clore config set api_key YOUR_API_KEY
```

***

## Étape 3 : Rechercher un GPU

### CLI

```bash
clore search --gpu "RTX 4090" --max-price 5.0 --sort price --limit 10
```

Vous verrez un tableau avec les ID des serveurs, les spécifications GPU, la RAM, le prix et la localisation.

### Python

```python
from clore_ai import CloreAI

client = CloreAI()

servers = client.marketplace(gpu="RTX 4090", max_price_usd=5.0)
for s in servers[:5]:
    print(f"Server {s.id}: {s.gpu_count}x {s.gpu_model} — ${s.price_usd:.4f}/h — {s.location}")
```

**Sortie :**

```
Server 142: 1x NVIDIA GeForce RTX 4090 — $0.0800/h — EU
Server 305: 1x NVIDIA GeForce RTX 4090 — $0.0950/h — US
Server 891: 2x NVIDIA GeForce RTX 4090 — $0.1200/h — EU
```

{% hint style="info" %}
**Astuce :** La `marketplace()` méthode filtre côté client. Vous pouvez aussi filtrer par `min_gpu_count`, `min_ram_gb`, et `available_only` (par défaut : `True`).
{% endhint %}

***

## Étape 4 : Déployer (Louer un serveur)

### CLI

```bash
clore deploy 142 \
  --image cloreai/ubuntu22.04-cuda12 \
  --type on-demand \
  --currency bitcoin \
  --ssh-password MySecurePass123 \
  --port 22:tcp \
  --port 8888:http
```

### Python

```python
order = client.create_order(
    server_id=142,
    image="cloreai/ubuntu22.04-cuda12",
    type="on-demand",
    currency="bitcoin",
    ssh_password="MySecurePass123",
    ports={"22": "tcp", "8888": "http"}
)

print(f"Order created! ID: {order.id}")
print(f"IP: {order.pub_cluster}")
print(f"Ports: {order.tcp_ports}")
```

{% hint style="warning" %}
**Le premier démarrage prend 1 à 5 minutes.** Le serveur télécharge l'image Docker et démarre les services. Si `pub_cluster` est `None`, attendez et vérifiez à nouveau avec `my_orders()`.
{% endhint %}

***

## Étape 5 : Se connecter via SSH

### CLI (connexion automatique)

```bash
clore ssh 38
```

La CLI recherche la commande, trouve l'IP publique et le port SSH, et exécute `ssh` pour vous.

### SSH manuel

```bash
ssh root@<pub_cluster> -p <ssh_port>
# Mot de passe : MySecurePass123
```

***

## Étape 6 : Nettoyage

Lorsque vous avez terminé, annulez la commande pour arrêter la facturation :

### CLI

```bash
clore cancel 38
```

### Python

```python
client.cancel_order(order_id=38, issue="Done with my work")
print("Order cancelled")
```

***

## Script complet : Rechercher → Déployer → Surveiller → Annuler

```python
from clore_ai import CloreAI
import time

client = CloreAI()  # Utilise la variable d'env CLORE_API_KEY

# 1. Trouver le RTX 4090 le moins cher
servers = client.marketplace(gpu="RTX 4090", max_price_usd=5.0)
servers.sort(key=lambda s: s.price_usd or float("inf"))

if not servers:
    print("Aucun RTX 4090 disponible à moins de 5 $/h")
    exit(1)

best = servers[0]
print(f"Meilleure offre : Server {best.id} — ${best.price_usd:.4f}/h — {best.location}")

# 2. Déployer
order = client.create_order(
    server_id=best.id,
    image="cloreai/ubuntu22.04-cuda12",
    type="on-demand",
    currency="bitcoin",
    ssh_password="MySecurePass123",
    ports={"22": "tcp"}
)
print(f"Order {order.id} created!")

# 3. Attendre l'attribution de l'IP
for _ in range(12):
    orders = client.my_orders()
    current = next((o for o in orders if o.id == order.id), None)
    if current and current.pub_cluster:
        print(f"Prêt ! SSH : ssh root@{current.pub_cluster} -p {current.tcp_ports.get('22', 22)}")
        break
    print("En attente du démarrage du serveur...")
    time.sleep(10)

# 4. ... faites votre travail ...

# 5. Annuler une fois terminé
client.cancel_order(order_id=order.id)
print("Commande annulée, facturation arrêtée.")
```

***

## Et après ?

| Guide                                                                   | Ce que vous apprendrez                                                         |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [Guide du SDK Python](/guides/guides_v2-fr/avance/python-sdk.md)        | Opérations asynchrones, marché spot, gestion des serveurs, gestion des erreurs |
| [Automatisation CLI](/guides/guides_v2-fr/avance/cli-automation.md)     | Scripts Bash, intégration CI/CD, déploiement en lot                            |
| [Intégration API](/guides/guides_v2-fr/avance/api-integration.md)       | Connectez les services IA exécutés sur Clore à vos applications                |
| [Comparaison GPU](/guides/guides_v2-fr/prise-en-main/gpu-comparison.md) | Choisir le bon GPU pour votre charge de travail                                |

***

**Bonne location de GPU ! 🚀**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-fr/prise-en-main/python-quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
