|
| 1 | +# SharpAPI Python SDK |
| 2 | + |
| 3 | +Official Python client for the [SharpAPI](https://sharpapi.io) real-time sports betting odds API. |
| 4 | + |
| 5 | +Get pre-computed +EV opportunities, arbitrage detection, middles, and live odds from 20+ sportsbooks — with Pinnacle as the sharp reference. |
| 6 | + |
| 7 | +## Install |
| 8 | + |
| 9 | +```bash |
| 10 | +pip install sharpapi |
| 11 | +``` |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +```python |
| 16 | +from sharpapi import SharpAPI |
| 17 | + |
| 18 | +client = SharpAPI("sk_live_xxx") |
| 19 | + |
| 20 | +# --- Arbitrage opportunities --- |
| 21 | +arbs = client.arbitrage.get(min_profit=1.0, league="nba") |
| 22 | +for arb in arbs.data: |
| 23 | + print(f"{arb.profit_percent:.2f}% profit — {arb.event_name}") |
| 24 | + for leg in arb.legs: |
| 25 | + print(f" {leg.sportsbook}: {leg.selection} @ {leg.odds_american} ({leg.stake_percent:.1f}%)") |
| 26 | + |
| 27 | +# --- +EV opportunities --- |
| 28 | +evs = client.ev.get(min_ev=3.0, sport="basketball") |
| 29 | +for opp in evs.data: |
| 30 | + print(f"+{opp.ev_percent:.1f}% EV on {opp.selection} @ {opp.sportsbook}") |
| 31 | + if opp.kelly_fraction: |
| 32 | + print(f" Kelly: {opp.kelly_fraction:.1%} of bankroll") |
| 33 | + |
| 34 | +# --- Best odds across books --- |
| 35 | +odds = client.odds.best(league="nba", market="moneyline") |
| 36 | +for line in odds.data: |
| 37 | + print(f"{line.home_team} vs {line.away_team}: {line.selection} {line.odds_american}") |
| 38 | +``` |
| 39 | + |
| 40 | +## Streaming |
| 41 | + |
| 42 | +Real-time SSE streaming for odds updates and opportunity alerts (requires WebSocket add-on): |
| 43 | + |
| 44 | +```python |
| 45 | +stream = client.stream.opportunities(league="nba") |
| 46 | + |
| 47 | +@stream.on("ev:detected") |
| 48 | +def on_ev(data): |
| 49 | + for opp in data: |
| 50 | + print(f"+EV: {opp['selection']} {opp['ev_percent']}% @ {opp['sportsbook']}") |
| 51 | + |
| 52 | +@stream.on("arb:detected") |
| 53 | +def on_arb(data): |
| 54 | + for arb in data: |
| 55 | + print(f"Arb: {arb['profit_percent']}% — {arb['event_name']}") |
| 56 | + |
| 57 | +stream.connect() # Blocks, processing events |
| 58 | +``` |
| 59 | + |
| 60 | +Or iterate over events: |
| 61 | + |
| 62 | +```python |
| 63 | +for event_type, data in stream.iter_events(): |
| 64 | + if event_type == "ev:detected": |
| 65 | + print(data) |
| 66 | +``` |
| 67 | + |
| 68 | +## All Resources |
| 69 | + |
| 70 | +```python |
| 71 | +# Odds |
| 72 | +client.odds.get(sport="basketball", league="nba") |
| 73 | +client.odds.best(league="nfl", market="moneyline") |
| 74 | +client.odds.comparison(event_id="abc123") |
| 75 | +client.odds.batch(event_ids=["abc123", "def456"]) |
| 76 | + |
| 77 | +# Opportunities |
| 78 | +client.ev.get(min_ev=2.0, sportsbook="draftkings") |
| 79 | +client.arbitrage.get(min_profit=0.5, sport="football") |
| 80 | +client.middles.get(sport="football", min_size=3.0) |
| 81 | +client.low_hold.get(max_hold=2.0) |
| 82 | + |
| 83 | +# Reference data |
| 84 | +client.sports.list() |
| 85 | +client.leagues.list(sport="basketball") |
| 86 | +client.sportsbooks.list() |
| 87 | +client.events.list(league="nba", live=True) |
| 88 | +client.events.search("Lakers") |
| 89 | + |
| 90 | +# Account |
| 91 | +client.account.me() # Tier, limits, features |
| 92 | +client.account.usage() # Request counts |
| 93 | + |
| 94 | +# Streaming |
| 95 | +client.stream.odds(league="nba") |
| 96 | +client.stream.opportunities(min_ev=3.0) |
| 97 | +client.stream.all(sport="basketball") |
| 98 | +client.stream.event("event_id_here") |
| 99 | +``` |
| 100 | + |
| 101 | +## Data Quality |
| 102 | + |
| 103 | +Every opportunity response includes staleness metadata to avoid acting on stale odds: |
| 104 | + |
| 105 | +```python |
| 106 | +arbs = client.arbitrage.get() |
| 107 | +for arb in arbs.data: |
| 108 | + if arb.possibly_stale: |
| 109 | + print(f" Skipping — odds may be stale ({arb.oldest_odds_age_seconds}s old)") |
| 110 | + continue |
| 111 | + if "LIVE_HIGH_PROFIT_SUSPICIOUS" in arb.warnings: |
| 112 | + print(f" Skipping — likely phantom arb") |
| 113 | + continue |
| 114 | + print(f"Actionable: {arb.profit_percent}%") |
| 115 | +``` |
| 116 | + |
| 117 | +## Rate Limits |
| 118 | + |
| 119 | +Rate limit info is available after every request: |
| 120 | + |
| 121 | +```python |
| 122 | +response = client.odds.get() |
| 123 | +print(f"Remaining: {client.rate_limit.remaining}/{client.rate_limit.limit}") |
| 124 | +print(f"Tier: {client.rate_limit.tier}") |
| 125 | +``` |
| 126 | + |
| 127 | +## Error Handling |
| 128 | + |
| 129 | +```python |
| 130 | +from sharpapi import ( |
| 131 | + SharpAPI, |
| 132 | + AuthenticationError, |
| 133 | + TierRestrictedError, |
| 134 | + RateLimitedError, |
| 135 | +) |
| 136 | + |
| 137 | +client = SharpAPI("sk_live_xxx") |
| 138 | + |
| 139 | +try: |
| 140 | + evs = client.ev.get() |
| 141 | +except AuthenticationError: |
| 142 | + print("Invalid API key") |
| 143 | +except TierRestrictedError as e: |
| 144 | + print(f"Upgrade to {e.required_tier} tier for this feature") |
| 145 | +except RateLimitedError as e: |
| 146 | + print(f"Rate limited — retry after {e.retry_after}s") |
| 147 | +``` |
| 148 | + |
| 149 | +## Odds Conversion Utilities |
| 150 | + |
| 151 | +```python |
| 152 | +from sharpapi import american_to_decimal, american_to_probability, decimal_to_american |
| 153 | + |
| 154 | +american_to_decimal(-110) # 1.909 |
| 155 | +american_to_decimal(150) # 2.5 |
| 156 | +american_to_probability(-110) # 0.524 |
| 157 | +decimal_to_american(2.5) # 150 |
| 158 | +``` |
| 159 | + |
| 160 | +## Requirements |
| 161 | + |
| 162 | +- Python 3.9+ |
| 163 | +- httpx |
| 164 | +- pydantic v2 |
| 165 | + |
| 166 | +## Links |
| 167 | + |
| 168 | +- [API Docs](https://docs.sharpapi.io) |
| 169 | +- [Dashboard](https://sharpapi.io/dashboard) |
| 170 | +- [Discord](https://discord.gg/sharpapi) |
0 commit comments