Getting Started with Python
Server-side StarkNet wallet and transfer operations with the Chipi Python SDK. Works with Django, Flask, FastAPI, and any Python backend.
Overview
The chipi-python SDK provides server-side wallet operations for Python backends. Use it with Django, Flask, FastAPI, or any Python framework to create wallets, check balances, transfer tokens, and purchase digital services. All transactions are gasless. The SDK handles StarkNet account abstraction and gas sponsorship.
Install
Install the Chipi Python SDK:
bashpip install chipi-pythonRequires Python 3.8+. The SDK provides both synchronous and asynchronous methods.
Authentication
Initialize the SDK with your API keys:
pythonfrom chipi import ChipiSDK
sdk = ChipiSDK(
public_key="pk_prod_YOUR_KEY",
secret_key="sk_prod_YOUR_KEY",
)Or set via environment variables:
bashexport CHIPI_PUBLIC_KEY=pk_prod_YOUR_KEY
export CHIPI_SECRET_KEY=sk_prod_YOUR_KEYBoth public and secret keys are used server-side. Never expose the sk_prod_ key to clients.
Create and Access Wallets
Create a wallet for an authenticated user:
pythonfrom chipi.types import CreateWalletParams
result = sdk.create_wallet(CreateWalletParams(
external_user_id="user_123",
chain="STARKNET",
wallet_type="CHIPI",
encrypt_key="user-passkey-or-pin",
))
print(result.public_key, result.tx_hash)Get an existing wallet:
pythonwallet = sdk.get_wallet(external_user_id="user_123")
print(wallet.public_key, wallet.wallet_type)Check balance:
pythonbalance = sdk.get_balance(
wallet_public_key="0x...",
chain="STARKNET",
token="USDC",
)
print(balance.formatted) # e.g. "10.50"Token Transfers
Transfer USDC, ETH, or STRK to any StarkNet address:
pythonfrom chipi.types import TransferParams
result = sdk.transfer(TransferParams(
encrypt_key="user-passkey-or-pin",
wallet_public_key="0x...",
token="USDC",
recipient="0x...",
amount="10",
chain="STARKNET",
))
print(result.tx_hash)Use human-readable amounts. The SDK handles decimal conversion. USDC has 6 decimals, ETH/STRK have 18.
Async Variants and SKU Purchases
All methods have async counterparts prefixed with a:
pythonresult = await sdk.acreate_wallet(params)
result = await sdk.atransfer(params)Purchase digital services (Mexico only):
pythonresult = sdk.purchase_sku(
encrypt_key="user-passkey-or-pin",
wallet_public_key="0x...",
sku_id="sku_123",
reference="5551234567",
amount="10",
)
print(result.tx_hash, result.purchase_id)Error Handling
The SDK provides specific exception types:
pythonfrom chipi.exceptions import ChipiTransactionError, ChipiApiError
try:
result = sdk.transfer(params)
except ChipiTransactionError as e:
print(f"Transaction failed: {e.tx_hash} - {e.message}")
except ChipiApiError as e:
print(f"API error {e.status_code}: {e.message}")- - ChipiTransactionError. On-chain execution failed (insufficient balance, invalid address, contract revert)
- - ChipiApiError. API-level error (invalid key, rate limit, network issue)
- - All transactions are gasless. Users never need ETH or STRK to transact
- - Default to
wallet_type: "CHIPI"for session key support