> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kash.bot/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Protocol SDK — overview

> kashdao-protocol-sdk — non-custodial Python SDK for the Kash market program on Solana. Bring your own RPC and keypair.

`kashdao-protocol-sdk` is the **direct-to-chain** Python SDK for Kash.
It talks straight to the Kash market program on Solana mainnet-beta, with the same trust model and
the same client shape as the TypeScript
[`@kashdao/protocol-sdk`](https://docs.kash.bot/developer-docs/protocol-sdk/overview).

Use it for Python trading bots, market makers, AI agents and notebook
analysis. For a hosted, API-key-authed integration instead, call the
[REST API](https://docs.kash.bot/developer-docs/rest-api/overview.md) directly.

> [!NOTE]
>
> The package is in beta (`0.3.0b2`, Solana only). Pin the version you test against. Positions from the earlier Base markets need `0.2.0b2`.

## Trust model

The package never holds keys, never sponsors fees and never contacts
ZeroID-hosted infrastructure. You bring the RPC endpoint and the signer
(a `solders` `Keypair`, or any object implementing the `SolanaSigner`
protocol). The SDK builds the instructions, asks your signer to sign,
and sends through your RPC.

## Install

```bash theme={null}
pip install kashdao-protocol-sdk
```

```python theme={null}
from kashdao_protocol_sdk import create_solana_client, keypair_signer
```

Requires Python 3.10 or later.

## Supported clusters

| Cluster | `cluster` | Market program | USDC mint |
| - | - | - | - |
| **mainnet-beta** | `"mainnet-beta"` | `Jr8Bd8efPfNYHW65vZrVzeLbYkzy1oo3QB3i8cYdDcy` | `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` |
| devnet | `"devnet"` | `J3tSyyhaeokZc9VnogXR9anQMeA9FjKn8fnnjrLTkuN5` | `6xNqPRTd9V71N8KBp1X3x87rEA2sLiLsDqU7gQ4MuwBe` (test stand-in) |

`mainnet-beta` is the default. Pass
`cluster=CustomSolanaDeployment(program_id=..., usdc_mint=...)` for a
local validator.

## Client surface

`create_solana_client(rpc_url=...)` returns an async client (use it with
`async with`, or call `await client.aclose()`):

| Method | What it does |
| - | - |
| `markets.get(ref)` | Decoded market: status, prices, probabilities |
| `markets.quote_buy` / `quote_sell` / `quote_redeem` | Exact quotes from the program's integer curve |
| `account.position` / `positions` / `usdc_balance` | Position balances and the self-custodial wallet's USDC balance |
| `protocol.config` / `template` / `templates` | Program config and market templates |
| `trades.build_buy` / `build_sell` / `build_redeem` / `build_redeem_cancelled` / `build_open_position` / `build_close_position` | A plan: the instructions plus the bounds they encode |
| `trades.simulate(plan, payer=...)` / `trades.send(plan, signer=...)` | Simulate unsigned, or sign, send and confirm |
| `trades.buy` / `sell` / `redeem` / `redeem_cancelled` / `open_position` / `close_position` | Build and send in one call, with the signer as trader |

Differences from the TypeScript SDK are ergonomic only: every client
method is `async`, names are `snake_case`, and amounts are plain `int`.

## Key concepts

* **Market references.** A market is named by its numeric id (`5`) or its
  market account address. The REST API's `contractAddress` for a Solana
  market is that address.
* **Amounts.** USDC is an atomic `int` with 6 decimals (`1_000_000` = 1
  USDC). Outcome balances are WAD `int`s with 18 decimals.
* **Positions are not SPL tokens.** Each position is a balance in a
  program account. `build_buy` opens it when missing, and
  `close_position` reclaims its rent once it is empty.
* **Slippage is mandatory.** Every trade takes `max_slippage_bps` or an
  explicit floor (`min_tokens_out_wad` / `min_amount_out_usdc`).
* **Errors** use the same class names and codes as the TypeScript SDK
  (`KashValidationError`, `KashSimulationRevertedError`,
  `KashTransactionOutcomeUnknownError`, …); see
  [Error handling](https://docs.kash.bot/developer-docs/protocol-sdk/error-handling.md).

## Where to next

> [card] [Quickstart](https://docs.kash.bot/developer-docs/protocol-sdk-python/quickstart.md)
>
> Read, quote, buy, sell and redeem from a keypair.

> [card] [Error handling](https://docs.kash.bot/developer-docs/protocol-sdk/error-handling.md)
>
> Which failures are safe to retry. Shared with the TypeScript SDK.

> [card] [TypeScript SDK](https://docs.kash.bot/developer-docs/protocol-sdk/overview.md)
>
> The same program, in TypeScript.

> [card] [Source](https://github.com/KashDAO/protocol-sdk-python)
>
> `KashDAO/protocol-sdk-python` on GitHub, with runnable examples.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.