SDK

Python SDK

Full Buff SDK for Python — same features as the TypeScript SDK.

Install

$pip install buff-sdkCopy

Quick Start

main.py
typescript
1from buff import calculate_round_up, calculate_fees, derive_wallet, PriceService
2
3# Calculate a round-up
4round_up, rounded_to, skipped, capped = calculate_round_up(27.63, 0.50)
5print(f"Round-up: ${round_up}") # $0.37
6
7# Full fee breakdown with real SOL price
8price_service = PriceService()
9sol_price = price_service.get_sol_price()
10breakdown = calculate_fees(27.63, sol_price, 0.50)
11print(f"Investing: ${breakdown.user_investment_usd}")
12
13# Derive Buff wallet (same as TypeScript SDK)
14signature = wallet.sign_message(b"Buff Portfolio Wallet v1")
15keypair = derive_wallet(signature)
16print(f"Buff wallet: {keypair.pubkey()}")

Modules

ModulePurpose
buff.feecalculate_round_up(), calculate_fees() — fixed-point math
buff.walletderive_wallet() — SHA-256 + Solana keypair from signature
buff.configPLAN_TIERS, token mints, RPC URLs, fee tiers
buff.pricePriceService — CoinGecko with TTL caching
buff.swapget_swap_quote() — Jupiter integration via httpx
buff.portfolioget_portfolio() — read onchain token balances
buff.eventsBuffEventEmitter — on/off/emit
buff.errorsBuffError, BuffPriceError, BuffSwapError, etc.
Note
The Python SDK produces the same deterministic wallet as the TypeScript SDK — same signature input always generates the same Buff wallet across languages.