Python SDK Guide

Complete Python SDK guide — sync/async clients, marketplace filtering, order lifecycle, spot market, wallet ops, and error handling

circle-check

For a quick-start tutorial with real examples, see Clore.ai Python SDK — Automate Your GPU Workflows in 5 Minutesarrow-up-right

Installation

pip install clore-ai

The SDK provides two clients:

  • CloreAI — synchronous (simpler, good for scripts)

  • AsyncCloreAI — asynchronous (faster for concurrent operations)

Both share the same methods and return the same Pydantic models.


Sync vs Async — When to Use Each

Use Case
Client
Why

Simple scripts, one-off tasks

CloreAI

Simpler code, no async/await

Monitoring loops

CloreAI

Sequential checks work fine

Bulk marketplace queries

AsyncCloreAI

Concurrent requests = faster

Batch order creation

AsyncCloreAI

Create multiple orders in parallel

Web applications

AsyncCloreAI

Non-blocking I/O

Sync Example

Async Example

Both clients support context managers for automatic cleanup:


Client Configuration

The SDK includes a built-in rate limiter:

  • General requests: 1 request/second

  • create_order: 5-second cooldown between calls

  • Rate limit errors (code 5): Automatic exponential backoff


Marketplace Filtering

The marketplace() method fetches all available servers and filters client-side:

Advanced Filtering (Client-Side)

For filters not built into the method, filter the returned Server objects yourself:

Server Model Fields

Each MarketplaceServer object has these attributes and convenience properties:

Field
Type
Description

id

int

Server ID (use this in create_order)

gpu_model

str | None

GPU description from specs (property)

gpu_count

int

Number of GPUs from gpu_array (property)

ram_gb

float | None

System RAM in GB (property, from specs.ram)

price_usd

float | None

On-demand price in USD (property, from price.usd.on_demand_usd)

spot_price_usd

float | None

Spot price in USD (property)

available

bool

Whether the server is not rented (property)

location

str | None

Country code from network specs (property)

specs

ServerSpecs | None

Hardware specs (cpu, ram, disk, gpu, net)

price

ServerPrice | None

Full pricing structure

rented

bool | None

Whether the server is currently rented


Order Management

Creating Orders

Full create_order Parameters

Parameter
Type
Required
Description

server_id

int

Server to rent

image

str

Docker image

type

str

"on-demand" or "spot"

currency

str

Payment currency (e.g., "bitcoin")

ssh_password

str

SSH password

ssh_key

str

SSH public key

ports

dict

Port mappings ({"22": "tcp"})

env

dict

Environment variables

jupyter_token

str

Jupyter notebook token

command

str

Startup command

spot_price

float

Spot bid price

required_price

float

Required price

autossh_entrypoint

str

Auto SSH entrypoint

Listing Orders

Order Model Fields

Field
Type
Description

id

int

Order ID

server_id

int | None

Rented server ID

type

str

"on-demand" or "spot"

status

str | None

Order status

image

str | None

Docker image

currency

str | None

Payment currency

price

float | None

Price

pub_cluster

str | None

Public IP / hostname

tcp_ports

dict | None

Port mappings (e.g., {"22": 50022})

created_at

str | None

Creation timestamp

Monitoring Orders

Cancelling Orders


Server Management (for Hosters)

If you host GPUs on Clore, the SDK lets you manage your servers:

List Your Servers

Get Server Config

Update Server Settings


Spot Market

Spot orders are 30–50% cheaper but can be interrupted if someone outbids you.

View Spot Offers

Create a Spot Order

Adjust Spot Price

Spot Bidding Strategy


Wallet Operations

Check Balances

Low-Balance Alert


Error Handling Best Practices

Exception Hierarchy

Basic Error Handling

Retry Pattern with Backoff

The SDK has built-in retries for rate limits and network errors (max_retries=3). For application-level retries:


Performance Tips

1. Reuse the Client

2. Use Async for Concurrent Operations

3. Async Batch Order Creation

circle-exclamation

4. Close Clients When Done


Complete Example: Auto-Scale GPU Workers


Next Steps

Last updated

Was this helpful?