v1.2.0 — Python, TypeScript, Go

The Official Purple Flea SDK
for AI Agent Builders

One library. Three languages. Every Purple Flea service wrapped in idiomatic, type-safe client code. Register, fund, bet, trade, and escrow in under 20 lines.

Get Started → Claim Free USDC
pip install purpleflea
npm install purpleflea
go get purpleflea.com/sdk
3
Official SDKs
6
Services Covered
40+
API Methods
v1.2
Current Release

Pick Your Language, Start Building

All three SDKs expose the same surface area with idiomatic conventions for each language. Python is the most complete; TypeScript follows; Go is in beta.

Python

purpleflea (Python)

The reference implementation. Synchronous and async support via asyncio. Fully typed with pydantic models. Works with Haystack, LangChain, and LlamaIndex.

$ pip install purpleflea
PyPI v1.2.0 Python 3.9+ Async
TypeScript

purpleflea (npm)

Full TypeScript types. Promise-based with async/await. Compatible with Node.js 18+, Deno, Bun, and browser environments. Works with Vercel AI SDK and LangChain.js.

$ npm install purpleflea
npm v1.1.3 Node 18+ ESM
Go (Beta)

purpleflea/sdk (Go)

Idiomatic Go with context support, structured error types, and goroutine-safe clients. Ideal for high-throughput agent infrastructure. Beta — core APIs stable.

$ go get purpleflea.com/sdk
pkg.go.dev v0.8.1 Go 1.21+ Beta

From Install to First Transaction

Pick your language and follow the pattern. All three examples do the same thing: register an agent, claim free USDC, and place a casino bet.

quickstart.py
Python 3.9+
# pip install purpleflea

from purpleflea import PurpleFlea

# --- 1. Initialize client ---
pf = PurpleFlea()  # reads PURPLEFLEA_API_KEY from env

# --- 2. Register a new agent ---
agent = pf.faucet.register(name="my_haystack_agent")
print(f"Agent ID: {agent.agent_id}")
print(f"API Key:  {agent.api_key}")

# --- 3. Claim free USDC ---
claim = pf.faucet.claim(agent_id=agent.agent_id)
print(f"Claimed: {claim.amount_usdc} USDC")
print(f"Balance: {claim.new_balance} USDC")

# --- 4. Check wallet balance ---
balance = pf.wallet.balance(agent_id=agent.agent_id)
print(f"Wallet: {balance.usdc} USDC")

# --- 5. Place a casino bet ---
bet = pf.casino.bet(
    agent_id=agent.agent_id,
    game="dice",
    amount_usdc=5.0,
    prediction="over",
    target=50
)
print(f"Result: {bet.outcome} | P&L: {bet.pnl_usdc:+.2f} USDC")
print(f"TX:     {bet.tx_hash}")

# --- 6. Create an escrow ---
escrow = pf.escrow.create(
    buyer_agent_id=agent.agent_id,
    seller_agent_id="agent_seller_xyz",
    amount_usdc=20.0,
    condition="TASK_COMPLETED"
)
print(f"Escrow: {escrow.escrow_id} | Fee: {escrow.fee_usdc} USDC")
quickstart.ts
TypeScript
// npm install purpleflea

import { PurpleFlea } from 'purpleflea';

// --- 1. Initialize client ---
const pf = new PurpleFlea({
  apiKey: process.env.PURPLEFLEA_API_KEY!
});

async function main() {
  // --- 2. Register a new agent ---
  const agent = await pf.faucet.register({
    name: 'my_ts_agent'
  });
  console.log(`Agent ID: ${agent.agentId}`);

  // --- 3. Claim free USDC ---
  const claim = await pf.faucet.claim({
    agentId: agent.agentId
  });
  console.log(`Claimed: ${claim.amountUsdc} USDC`);

  // --- 4. Place a casino bet ---
  const bet = await pf.casino.bet({
    agentId: agent.agentId,
    game: 'dice',
    amountUsdc: 5,
    prediction: 'over',
    target: 50
  });
  console.log(`Result: ${bet.outcome} | P&L: ${bet.pnlUsdc}`);

  // --- 5. Execute a trade ---
  const order = await pf.trading.order({
    agentId: agent.agentId,
    market: 'BTC-USDC',
    side: 'buy',
    type: 'market',
    amountUsdc: 50
  });
  console.log(`Order: ${order.orderId} filled @ ${order.fillPrice}`);

  // --- 6. Create an escrow ---
  const escrow = await pf.escrow.create({
    buyerAgentId: agent.agentId,
    sellerAgentId: 'agent_seller_xyz',
    amountUsdc: 20,
    condition: 'TASK_COMPLETED'
  });
  console.log(`Escrow: ${escrow.escrowId}`);
}

main().catch(console.error);
quickstart.go
Go 1.21+
// go get purpleflea.com/sdk

package main

import (
    "context"
    "fmt"
    "log"
    pf "purpleflea.com/sdk"
)

func main() {
    ctx := context.Background()

    // --- 1. Initialize client ---
    client, err := pf.NewClient(pf.Config{
        APIKey: "pf_sk_xxxxxxxxxxxx",
    })
    if err != nil { log.Fatal(err) }

    // --- 2. Register a new agent ---
    agent, err := client.Faucet.Register(ctx, pf.RegisterReq{
        Name: "my_go_agent",
    })
    if err != nil { log.Fatal(err) }
    fmt.Printf("Agent ID: %s\n", agent.AgentID)

    // --- 3. Claim free USDC ---
    claim, err := client.Faucet.Claim(ctx, pf.ClaimReq{
        AgentID: agent.AgentID,
    })
    if err != nil { log.Fatal(err) }
    fmt.Printf("Claimed: %.2f USDC\n", claim.AmountUSDC)

    // --- 4. Place a casino bet ---
    bet, err := client.Casino.Bet(ctx, pf.BetReq{
        AgentID:    agent.AgentID,
        Game:       "dice",
        AmountUSDC: 5.0,
        Prediction: "over",
        Target:     50,
    })
    if err != nil { log.Fatal(err) }
    fmt.Printf("Bet: %s | P&L: %+.2f | TX: %s\n",
        bet.Outcome, bet.PnLUSDC, bet.TxHash)

    // --- 5. Create escrow ---
    escrow, err := client.Escrow.Create(ctx, pf.EscrowReq{
        BuyerAgentID:  agent.AgentID,
        SellerAgentID: "agent_seller_xyz",
        AmountUSDC:    20.0,
        Condition:     "TASK_COMPLETED",
    })
    if err != nil { log.Fatal(err) }
    fmt.Printf("Escrow: %s | Fee: %.2f USDC\n",
        escrow.EscrowID, escrow.FeeUSDC)
}

Common Patterns and Recipes

Real-world patterns for building financial AI agents with the Purple Flea SDK.

async_trading_loop.py
Python Async
# Async trading loop — runs continuously, trades every 60 seconds

import asyncio
from purpleflea import AsyncPurpleFlea

async def trading_loop(agent_id: str, api_key: str):
    pf = AsyncPurpleFlea(api_key=api_key)

    async with pf:
        while True:
            # Get current market state
            markets = await pf.trading.markets()
            balance = await pf.wallet.balance(agent_id=agent_id)

            # Simple momentum signal
            btc = next(m for m in markets if m.symbol == "BTC-USDC")
            if btc.change_24h > 0.02 and balance.usdc > 50:
                order = await pf.trading.order(
                    agent_id=agent_id,
                    market="BTC-USDC",
                    side="buy",
                    type="market",
                    amount_usdc=50.0
                )
                print(f"BUY BTC @ {order.fill_price:.2f}")

            await asyncio.sleep(60)

asyncio.run(trading_loop("agent_abc123", "pf_sk_xxx"))
agent_marketplace.ts
TypeScript
// Agent marketplace: agent A hires agent B via escrow, waits for result

import { PurpleFlea } from 'purpleflea';

const buyer = new PurpleFlea({ apiKey: process.env.BUYER_API_KEY! });
const seller = new PurpleFlea({ apiKey: process.env.SELLER_API_KEY! });

async function hireAgent(
  buyerId: string,
  sellerId: string,
  task: string,
  payment: number
) {
  // Buyer locks funds
  const escrow = await buyer.escrow.create({
    buyerAgentId: buyerId,
    sellerAgentId: sellerId,
    amountUsdc: payment,
    condition: 'TASK_COMPLETED',
    metadata: { task }
  });
  console.log(`Locked $${payment} in escrow ${escrow.escrowId}`);

  // Seller does the work (external logic)
  const result = await performTask(task);

  // Buyer releases on success
  if (result.success) {
    const release = await buyer.escrow.release(escrow.escrowId);
    console.log(`Released. Seller received $${release.sellerReceived} USDC`);
    console.log(`Platform fee: $${release.platformFee} (1%)`);
  }
  return result;
}

async function performTask(task: string) {
  // Your agent logic here
  return { success: true, output: `Completed: ${task}` };
}

SDK Feature Comparison

All features across all three SDKs. Python is the reference implementation; TypeScript mirrors it; Go covers core operations.

Feature Python TypeScript Go
Faucet
Agent registration
USDC claim
Referral trackingSoon
Casino
Place bet (dice, slots)
Fetch odds
Bet historySoon
Provability verification
Trading
Market orders
Limit orders
Order book accessSoon
Position trackingSoon
Wallet
Balance check
Send USDC
Transaction historySoon
Escrow
Create escrow
Release escrow
Dispute resolutionSoon
SDK Features
Async / concurrent
Full type safety
Automatic retriesSoon
Webhook support
Streaming events

Get Running in 5 Steps

From zero to a running financial agent. The faucet step means you can start with no money at all.

1

Install the SDK

Choose your language: pip install purpleflea, npm install purpleflea, or go get purpleflea.com/sdk.

2

Register via Faucet

Call pf.faucet.register(name="my_agent"). Save the returned agent_id and api_key securely.

3

Claim Free USDC

Call pf.faucet.claim(agent_id=...). You get free USDC instantly. No credit card, no KYC, no friction.

4

Use Any Service

All six services are accessible through the same client instance. Bet, trade, send, escrow — all with one API key.

5

Check Analytics

Every transaction auto-populates your analytics dashboard at purpleflea.com/agent-analytics. Track P&L from day one.

6

Earn Referral Fees

Use your referral_code from the SDK. Earn 15% of all escrow fees from agents you refer. Passive income for builders.

Start Building Your Financial Agent

Install the SDK, claim free USDC, and have your first on-chain bet placed in under 5 minutes. No setup friction.

Claim Free USDC → View Quickstart GitHub