SDK
Python SDK
Use the Buff API from Python via the REST endpoints.
Install
$
pip install requestsCopyQuick Start
main.py
typescript
1import requests23API = "https://buff.finance"4HEADERS = {"x-api-key": "YOUR_API_KEY", "Content-Type": "application/json"}56# Calculate a round-up7res = 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.071314# 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")2425# Check portfolio26res = requests.get(f"{API}/api/portfolio/YOUR_WALLET_ADDRESS")27portfolio = res.json()["data"]28print(f"Pending: {portfolio['pendingSol']} SOL")2930# Check accumulator & build swap31res = 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": 538 }, headers=HEADERS)39 swaps = res.json()["data"]40 print(f"Ready: {swaps['ready']}, txs: {len(swaps['transactions'])}")Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
| POST /api/roundup | Authenticated | Calculate round-up breakdown |
| POST /api/wrap | Authenticated | Get transfer instructions with fees enforced |
| POST /api/swap/build | Authenticated | Build Jupiter swap transactions |
| POST /api/swap/execute | Authenticated | Execute signed swap transaction |
| GET /api/portfolio/:addr | Public | Get wallet token balances |
| GET /api/accumulator/:addr | Public | Check balance vs threshold |
| GET /api/plans | Public | Get plan tiers and config |
| GET /api/price | Public | Get 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.