Search docs

Find a documentation page

Python SDK

requests-based reference for integrating the marketplace API from Python.

Status

There is no first-party Python SDK package. The marketplace API is plain JSON over HTTPS, so requests (or httpx) is enough. The patterns below mirror the canonical Rust SDK contract.

Minimal client

import os
import uuid
from typing import Any

import requests


class MarketplaceClient:
    def __init__(self, base_url: str, token: str) -> None:
        self.base_url = base_url.rstrip("/")
        self._session = requests.Session()
        self._session.headers.update({"Authorization": f"Bearer {token}"})

    def list_validators(self, limit: int = 20) -> list[dict[str, Any]]:
        r = self._session.get(
            f"{self.base_url}/v1/validators",
            params={"limit": limit},
            timeout=10,
        )
        r.raise_for_status()
        return r.json()["data"]

    def create_lease(self, payload: dict[str, Any]) -> dict[str, Any]:
        r = self._session.post(
            f"{self.base_url}/v1/leases",
            json=payload,
            headers={"Idempotency-Key": str(uuid.uuid4())},
            timeout=10,
        )
        r.raise_for_status()
        return r.json()["data"]


if __name__ == "__main__":
    client = MarketplaceClient(
        base_url=os.environ["MARKETPLACE_API_URL"],
        token=os.environ["MARKETPLACE_TOKEN"],
    )
    for v in client.list_validators():
        print(v["public_id"], v["uptime_30d_pct"])

Notes

  • The marketplace accepts any opaque string up to 64 chars for the idempotency key. UUID4 is fine for ad-hoc Python scripts, though ULID makes time-ordered debugging easier.
  • For production use, prefer httpx.AsyncClient if your service is asyncio-based. requests is shown here for clarity.
  • Type stubs can be generated from the committed OpenAPI spec with datamodel-codegen --input openapi.json --output schemas.py.