Quick Start
Go from zero to your first API call in under 60 seconds.
Prerequisites
Before continuing, make sure you have:
- Python 3.8+ installed
- StakeAPI installed (
pip install stakeapi) - A Stake.com account with an access token
π‘ Don't have a Stake.com account yet? Sign up here to get started and unlock all API features.
Your First Script
Create a file called my_first_script.py:
import asyncio
from stakeapi import StakeAPI
async def main():
# Replace with your actual access token
async with StakeAPI(access_token="your_access_token_here") as client:
# 1. Get your balance
balance = await client.get_user_balance()
print("π° Your Balance:")
for currency, amount in balance["available"].items():
if amount > 0:
print(f" {currency.upper()}: {amount}")
# 2. Browse casino games
games = await client.get_casino_games(category="slots")
print(f"\nπ° Found {len(games)} slot games!")
for game in games[:5]:
print(f" - {game.name} by {game.provider}")
# 3. Check sports events
events = await client.get_sports_events(sport="football")
print(f"\nβ½ Found {len(events)} football events!")
for event in events[:3]:
print(f" - {event.home_team} vs {event.away_team}")
asyncio.run(main())
Run it:
python my_first_script.py
Using Environment Variables
For a production-ready setup, use environment variables instead of hardcoding tokens:
import asyncio
import os
from dotenv import load_dotenv
from stakeapi import StakeAPI
load_dotenv() # Load from .env file
async def main():
token = os.getenv("STAKE_ACCESS_TOKEN")
if not token:
print("Set STAKE_ACCESS_TOKEN environment variable!")
return
async with StakeAPI(access_token=token) as client:
balance = await client.get_user_balance()
print(balance)
asyncio.run(main())
Understanding the Async Pattern
StakeAPI is built with async/await for maximum performance. Hereβs why:
# β
CORRECT β Using async context manager
async with StakeAPI(access_token=token) as client:
result = await client.get_user_balance()
# β
CORRECT β Manual session management
client = StakeAPI(access_token=token)
await client._create_session()
try:
result = await client.get_user_balance()
finally:
await client.close()
# β WRONG β Forgetting to await
async with StakeAPI(access_token=token) as client:
result = client.get_user_balance() # This returns a coroutine, not the result!
Multiple Concurrent Requests
One of the biggest advantages of async is making multiple requests simultaneously:
import asyncio
from stakeapi import StakeAPI
async def main():
async with StakeAPI(access_token="your_token") as client:
# Run 3 requests at the same time!
balance, games, events = await asyncio.gather(
client.get_user_balance(),
client.get_casino_games(),
client.get_sports_events(),
)
print(f"Balance: {balance}")
print(f"Games: {len(games)}")
print(f"Events: {len(events)}")
asyncio.run(main())
Error Handling
Always handle errors in production code:
import asyncio
from stakeapi import StakeAPI
from stakeapi.exceptions import (
StakeAPIError,
AuthenticationError,
RateLimitError,
)
async def main():
async with StakeAPI(access_token="your_token") as client:
try:
balance = await client.get_user_balance()
print(balance)
except AuthenticationError:
print("Invalid or expired token. Get a new one from stake.com")
except RateLimitError:
print("Too many requests. Wait a moment and try again.")
except StakeAPIError as e:
print(f"API error: {e}")
asyncio.run(main())
π¬ Join the StakeAPI Community on Discord
Get help, share your projects, discuss strategies, and stay up to date with the latest StakeAPI news.
Join Our Discord Server βWhatβs Next?
Now that youβve made your first API call, explore the full power of StakeAPI:
| Guide | Description |
|---|---|
| Casino Games | Browse and analyze casino games |
| Sports Betting | Access sports events and odds |
| User Account | Manage your profile and balance |
| Betting API | Place bets and track history |
| Advanced Usage | Build analytics and automation tools |
| API Reference | Complete method documentation |
Pro tip: Combine StakeAPI with data visualization libraries like
matplotliborplotlyto create stunning dashboards of your Stake.com activity. Sign up on Stake.com to get started!