Skip to main content

purpleflea

Python SDK for the Purple Flea Casino, Trading & Wallet APIs.

Installation

pip install purpleflea

Quick Start

Casino

from purpleflea import CasinoClient

# Defaults to http://80.78.27.26:3000
casino = CasinoClient("your-api-key")

# Register a new account
casino.register("alice", "alice@example.com")

# Deposit funds
casino.deposit(100.0, currency="USDC")

# List available games
games = casino.list_games()

# Play a round
result = casino.play("dice", bet_amount=5.0)

# Check balance & withdraw
balance = casino.get_balance()
casino.withdraw(50.0)

# Referrals
ref = casino.create_referral()
casino.redeem_referral("REF123")

casino.close()

Trading

from purpleflea import TradingClient

# Defaults to http://80.78.27.26:3003
trading = TradingClient("your-api-key")

# Register a new account
trading.register("bob", "bob@example.com")

# Browse markets
markets = trading.list_markets()
btc = trading.get_market("BTC-USD")
book = trading.get_orderbook("BTC-USD")

# Open a long position
pos = trading.open_position("BTC-USD", side="long", size=0.5)

# Check position and close
details = trading.get_position(pos["position_id"])
trading.close_position(pos["position_id"])

# Referrals
trading.create_referral()
trading.redeem_referral("TREF1")

trading.close()

Wallet

from purpleflea import WalletClient

# Defaults to http://80.78.27.26:3000
wallet = WalletClient("your-api-key")

# Get balance
balance = wallet.get_balance()

# Get deposit address for BTC
addr = wallet.get_address("BTC")

# Deposit USDC
wallet.deposit(500.0, currency="USDC")

# Withdraw to external address
wallet.withdraw(100.0, address="0xYourAddress", currency="USDC")

# Transaction history
txns = wallet.list_transactions(limit=20)

# Transfer between accounts
wallet.transfer(to_account="carol", amount=25.0)

wallet.close()

Context Manager

All clients support context managers for automatic cleanup:

from purpleflea import CasinoClient

with CasinoClient("your-api-key") as casino:
    casino.deposit(50.0)
    result = casino.play("dice", bet_amount=10.0)

Custom Base URL

from purpleflea import CasinoClient, TradingClient

casino = CasinoClient("your-api-key", base_url="http://80.78.27.26:3000")
trading = TradingClient("your-api-key", base_url="http://80.78.27.26:3003")

Error Handling

from purpleflea import CasinoClient, APIError

try:
    with CasinoClient("your-api-key") as casino:
        casino.play("invalid-game", bet_amount=10.0)
except APIError as e:
    print(f"API error {e.status_code}: {e.message}")

API Reference

CasinoClient(api_key, base_url=None, timeout=30.0)

Default base URL: http://80.78.27.26:3000. Routes use the /api/v1/ prefix.

Method Description
register(username, email) Register a new player
get_account() Get account details
deposit(amount, currency="USDC") Deposit funds
withdraw(amount, currency="USDC") Withdraw funds
get_balance() Get wallet balance
list_games() List available games
get_game(game_id) Get game details
play(game_id, bet_amount) Play a round
get_game_history() Get past results
create_referral() Generate referral code
list_referrals() List referrals
redeem_referral(code) Redeem a referral code

TradingClient(api_key, base_url=None, timeout=30.0)

Default base URL: http://80.78.27.26:3003. Routes use the /v1/ prefix.

Method Description
register(username, email) Register a new trader
get_account() Get account details
list_markets() List available markets
get_market(market_id) Get market details
get_orderbook(market_id) Get order book
open_position(market_id, side, size) Open a position
close_position(position_id) Close a position
get_position(position_id) Get position details
list_positions() List open positions
create_referral() Generate referral code
list_referrals() List referrals
redeem_referral(code) Redeem a referral code

WalletClient(api_key, base_url=None, timeout=30.0)

Default base URL: http://80.78.27.26:3000. Routes use the /api/v1/wallet/ prefix.

Method Description
get_balance() Get balance across all currencies
get_address(currency) Get deposit address for a currency
deposit(amount, currency="USDC") Initiate a deposit
get_deposit(deposit_id) Get deposit status
list_deposits() List all deposits
withdraw(amount, address, currency="USDC") Withdraw to external address
get_withdrawal(withdrawal_id) Get withdrawal status
list_withdrawals() List all withdrawals
list_transactions(limit=50) List all transactions
get_transaction(transaction_id) Get transaction details
transfer(to_account, amount, currency="USDC") Transfer to another account

Changelog

0.2.1

0.2.0

  • Added WalletClient with full deposit/withdrawal/transfer support
  • Set correct default base URLs: casino http://80.78.27.26:3000, trading http://80.78.27.26:3003
  • Promoted to Beta status

0.1.0

  • Initial release with CasinoClient and TradingClient

Development

git clone https://github.com/purple-flea/purpleflea-py.git
cd purpleflea-py
pip install -e ".[dev]"
pytest

License

MIT

Metadata

Release files for purpleflea 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for purpleflea 0.2.1
File Size Uploaded
purpleflea-0.2.1.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for purpleflea 0.2.1
File Interpreter ABI Platform
purpleflea-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / purpleflea-0.2.1.tar.gz

Download URL purpleflea-0.2.1.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
25d022a97f7c0be3dd68c19778adc95d33518787e022c620d68c4a54b315ea91
BLAKE2b-256 checksum
How to use checksums
ee762066f37318391281ba20aa5d1273c27323b0217ec0885ff8905335ff148c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / purpleflea-0.2.1-py3-none-any.whl

Download URL purpleflea-0.2.1-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f890a5d37d3816b4416c91555ebdcff16883b9dde5db0097b84db1345011ef9c
BLAKE2b-256 checksum
How to use checksums
e4eb500b61564a043298ec6853a348651bdc96704176e71e77729d1e4ba698c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page