SDK

Python SDK

Use the Buff API from Python via the REST endpoints.

Install

$pip install requestsCopy

Quick Start

main.py
typescript
1import requests
2
3API = "https://buff.finance"
4HEADERS = {"x-api-key": "YOUR_API_KEY", "Content-Type": "application/json"}
5
6# Calculate a round-up
7res = requests.post(f"{API}/api/roundup", json={
8 "txValueUsd": 27.63,
9 "plan": "sprout"
10}, headers=HEADERS)
11data = res.json()["data"]
12print(f"Round-up: ${data['roundUpUsd']}") # $0.07
13
14# Get wrap instructions (server builds transfers with fees)
15res = requests.post(f"{API}/api/wrap", json={
16 "txValueUsd": 27.63,
17 "userPubkey": "YOUR_PUBKEY",
18 "buffWalletPubkey": "BUFF_WALLET_PUBKEY",
19 "plan": "sprout"
20}, headers=HEADERS)
21wrap = res.json()["data"]
22print(f"Instructions: {len(wrap['instructions'])}")
23print(f"Fee: {wrap['breakdown']['buffFeeLamports']} lamports")
24
25# Check portfolio
26res = requests.get(f"{API}/api/portfolio/YOUR_WALLET_ADDRESS")
27portfolio = res.json()["data"]
28print(f"Pending: {portfolio['pendingSol']} SOL")
29
30# Check accumulator & build swap
31res = requests.get(f"{API}/api/accumulator/BUFF_WALLET?threshold=5")
32acc = res.json()["data"]
33if acc["thresholdReached"]:
34 res = requests.post(f"{API}/api/swap/build", json={
35 "buffWalletPubkey": "BUFF_WALLET",
36 "targetAsset": "BTC",
37 "threshold": 5
38 }, headers=HEADERS)
39 swaps = res.json()["data"]
40 print(f"Ready: {swaps['ready']}, txs: {len(swaps['transactions'])}")

Endpoints

EndpointMethodPurpose
POST /api/roundupAuthenticatedCalculate round-up breakdown
POST /api/wrapAuthenticatedGet transfer instructions with fees enforced
POST /api/swap/buildAuthenticatedBuild Jupiter swap transactions
POST /api/swap/executeAuthenticatedExecute signed swap transaction
GET /api/portfolio/:addrPublicGet wallet token balances
GET /api/accumulator/:addrPublicCheck balance vs threshold
GET /api/plansPublicGet plan tiers and config
GET /api/pricePublicGet current crypto prices
Note
All fee logic runs server-side. The Python client just calls the REST API — no sensitive logic needed. Auth via API key or wallet signature headers.