### Installation Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Install the Odds-API.io Python SDK using pip. ```APIDOC ## Installation Install the SDK from PyPI using pip. ```bash pip install odds-api-io ``` ``` -------------------------------- ### Install Odds-API.io Python SDK Source: https://github.com/odds-api-io/odds-api-python/blob/main/README.md Use pip to install the odds-api-io package. This is the first step to using the SDK. ```bash pip install odds-api-io ``` -------------------------------- ### GET /value_bets Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Finds value betting opportunities with positive expected value. ```APIDOC ## GET /value_bets ### Description Finds value betting opportunities with positive expected value based on true probability analysis. ### Parameters #### Query Parameters - **bookmaker** (string) - Required - The bookmaker slug to analyze. - **include_event_details** (boolean) - Optional - Whether to include detailed event information. ### Response - **expectedValue** (float) - The calculated expected value percentage. - **outcome** (string) - The specific outcome to bet on. - **odds** (float) - The odds offered. - **impliedProbability** (float) - The probability implied by the odds. - **trueProbability** (float) - The calculated true probability. ``` -------------------------------- ### Get Participants Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves participants (teams/players) for a sport with optional search filtering. ```APIDOC ## GET /participants ### Description Retrieves participants (teams/players) for a sport with optional search filtering. ### Method GET ### Endpoint /participants ### Parameters #### Query Parameters - **sport** (string) - Required - The sport to retrieve participants for (e.g., "basketball"). - **search** (string) - Optional - A keyword to filter participants by name. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: # Get all basketball participants participants = client.get_participants(sport="basketball") print(f"Total participants: {len(participants)}") # Search for specific teams warriors = client.get_participants(sport="basketball", search="Warriors") for team in warriors: print(f"Team: {team['name']}") ``` ### Response #### Success Response (200) - **participants** (array) - A list of participant objects. - **id** (integer) - The unique identifier of the participant. - **name** (string) - The name of the participant (team or player). - **sport** (string) - The sport the participant belongs to. - **league** (string) - The league the participant belongs to. #### Response Example ```json [ { "id": 3428, "name": "Golden State Warriors", "sport": "basketball", "league": "usa-nba" } ] ``` ``` -------------------------------- ### Initialize and Use Asynchronous AsyncOddsAPIClient Source: https://github.com/odds-api-io/odds-api-python/blob/main/README.md Initialize the asynchronous client using an async context manager. Use this client to fetch sports, events, and value bets asynchronously. The async context manager handles client setup and teardown. ```python import asyncio from odds_api import AsyncOddsAPIClient async def main(): # Use async context manager async with AsyncOddsAPIClient(api_key="your_api_key_here") as client: # Get sports sports = await client.get_sports() # Get upcoming events events = await client.get_events(sport="basketball", league="usa-nba") # Find value bets value_bets = await client.get_value_bets( bookmaker="singbet", include_event_details=True ) print(f"Found {len(value_bets)} value betting opportunities") # Run async code asyncio.run(main()) ``` -------------------------------- ### Get participant by ID Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Fetches detailed information for a specific participant using their unique ID. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: participant = client.get_participant_by_id(participant_id=3428) print(f"Name: {participant.get('name')}") print(f"Sport: {participant.get('sport')}") print(f"League: {participant.get('league')}") ``` -------------------------------- ### GET /live_events Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves all currently live in-play events for a specific sport with real-time data. ```APIDOC ## GET /live_events Retrieves all currently live in-play events for a specific sport with real-time data. ### Method GET ### Endpoint /live_events ### Parameters #### Query Parameters - **api_key** (string) - Required - Your Odds-API.io API key. - **sport** (string) - Required - The slug of the sport to retrieve live events for. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: live_events = client.get_live_events(sport="basketball") if live_events: print(f"Found {len(live_events)} live basketball games") for event in live_events: home = event['home'] away = event['away'] print(f"LIVE: {away} vs {home}") else: print("No live games at the moment") ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the event. - **sport** (string) - The sport slug. - **league** (string) - The league slug. - **home** (string) - The home team name. - **away** (string) - The away team name. - **startTime** (string) - The start time of the event in ISO 8601 format. - **status** (string) - The status of the event ('upcoming', 'in-play', 'completed'). - **bookmakers** (array) - An array of bookmakers offering odds for the event. - **key** (string) - The bookmaker slug. - **title** (string) - The bookmaker name. - **odds** (array) - An array of odds for different markets. #### Response Example ```json [ { "id": 67890, "sport": "basketball", "league": "usa-nba", "home": "Miami Heat", "away": "Boston Celtics", "startTime": "2024-01-14T20:00:00Z", "status": "in-play", "bookmakers": [ { "key": "draftkings", "title": "DraftKings", "odds": [ { "name": "H2H", "outcomes": [ {"name": "Miami Heat", "price": 1.50}, {"name": "Boston Celtics", "price": 2.50} ] } ] } ] } ] ``` ``` -------------------------------- ### GET /events/{eventId} Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves detailed information for a specific event by its unique identifier. ```APIDOC ## GET /events/{eventId} Retrieves detailed information for a specific event by its unique identifier. ### Method GET ### Endpoint /events/{eventId} ### Parameters #### Path Parameters - **eventId** (integer) - Required - The unique identifier of the event. #### Query Parameters - **api_key** (string) - Required - Your Odds-API.io API key. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: event = client.get_event_by_id(event_id=12345) print(f"Event ID: {event.get('id')}") print(f"Status: {event.get('status')}") print(f"Home: {event.get('home')}") print(f"Away: {event.get('away')}") if 'participants' in event: print("Participants:") for participant in event['participants']: print(f" - {participant['name']}") ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the event. - **sport** (string) - The sport slug. - **league** (string) - The league slug. - **home** (string) - The home team name. - **away** (string) - The away team name. - **startTime** (string) - The start time of the event in ISO 8601 format. - **status** (string) - The status of the event ('upcoming', 'in-play', 'completed'). - **participants** (array) - An array of participants in the event. - **id** (integer) - The participant ID. - **name** (string) - The participant name. - **isHome** (boolean) - Whether the participant is the home team. - **isAway** (boolean) - Whether the participant is the away team. - **bookmakers** (array) - An array of bookmakers offering odds for the event. - **key** (string) - The bookmaker slug. - **title** (string) - The bookmaker name. - **odds** (array) - An array of odds for different markets. #### Response Example ```json { "id": 12345, "sport": "basketball", "league": "usa-nba", "home": "Los Angeles Lakers", "away": "Golden State Warriors", "startTime": "2024-01-15T03:30:00Z", "status": "upcoming", "participants": [ {"id": 101, "name": "Golden State Warriors", "isHome": false, "isAway": true}, {"id": 102, "name": "Los Angeles Lakers", "isHome": true, "isAway": false} ], "bookmakers": [ { "key": "bet365", "title": "bet365", "odds": [ { "name": "H2H", "outcomes": [ {"name": "Golden State Warriors", "price": 2.10}, {"name": "Los Angeles Lakers", "price": 1.75} ] } ] } ] } ``` ``` -------------------------------- ### GET /sports Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves all available sports from the Odds-API.io platform with their identifiers and metadata. ```APIDOC ## GET /sports Retrieves all available sports from the Odds-API.io platform with their identifiers and metadata. ### Method GET ### Endpoint /sports ### Parameters #### Query Parameters - **api_key** (string) - Required - Your Odds-API.io API key. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: sports = client.get_sports() for sport in sports: print(f"Sport: {sport['name']} (slug: {sport['slug']})") ``` ### Response #### Success Response (200) - **name** (string) - The name of the sport. - **slug** (string) - The unique identifier for the sport. #### Response Example ```json [ { "name": "Basketball", "slug": "basketball" }, { "name": "American Football", "slug": "american-football" }, { "name": "Tennis", "slug": "tennis" }, { "name": "Baseball", "slug": "baseball" } ] ``` ``` -------------------------------- ### Get Bookmakers Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves all available bookmakers supported by the platform. ```APIDOC ## GET /bookmakers ### Description Retrieves all available bookmakers supported by the platform. ### Method GET ### Endpoint /bookmakers ### Parameters None ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: bookmakers = client.get_bookmakers() print(f"Total bookmakers: {len(bookmakers)}") for bookie in bookmakers[:10]: print(f"- {bookie['name']} (slug: {bookie.get('slug')})") ``` ### Response #### Success Response (200) - **bookmakers** (array) - A list of available bookmaker objects. - **name** (string) - The name of the bookmaker. - **slug** (string) - The unique slug identifier for the bookmaker. #### Response Example ```json [ { "name": "Bet365", "slug": "bet365" }, { "name": "SingBet", "slug": "singbet" } ] ``` ``` -------------------------------- ### GET /leagues Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves all leagues for a specific sport, allowing you to filter events by specific competitions. ```APIDOC ## GET /leagues Retrieves all leagues for a specific sport, allowing you to filter events by specific competitions. ### Method GET ### Endpoint /leagues ### Parameters #### Query Parameters - **api_key** (string) - Required - Your Odds-API.io API key. - **sport** (string) - Required - The slug of the sport to retrieve leagues for. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: leagues = client.get_leagues(sport="basketball") for league in leagues: print(f"League: {league['name']} (slug: {league['slug']})") ``` ### Response #### Success Response (200) - **name** (string) - The name of the league. - **slug** (string) - The unique identifier for the league. #### Response Example ```json [ { "name": "NBA", "slug": "usa-nba" }, { "name": "EuroLeague", "slug": "euroleague" }, { "name": "NCAA", "slug": "usa-ncaa" } ] ``` ``` -------------------------------- ### GET /arbitrage_bets Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Finds arbitrage betting opportunities across multiple bookmakers to guarantee profit. ```APIDOC ## GET /arbitrage_bets ### Description Finds arbitrage betting opportunities across multiple bookmakers where you can guarantee profit regardless of outcome. ### Parameters #### Query Parameters - **bookmakers** (string) - Required - Comma-separated list of bookmaker slugs. - **limit** (integer) - Optional - Maximum number of results to return. - **include_event_details** (boolean) - Optional - Whether to include detailed event information. ### Response - **profitPercentage** (float) - The guaranteed profit percentage. - **bets** (array) - List of required bets to execute the arbitrage. - **event** (object) - Optional - Event details if requested. ``` -------------------------------- ### GET /events Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves events with optional filters for league, status, date range, bookmaker, and participant. ```APIDOC ## GET /events Retrieves events with optional filters for league, status, date range, bookmaker, and participant. ### Method GET ### Endpoint /events ### Parameters #### Query Parameters - **api_key** (string) - Required - Your Odds-API.io API key. - **sport** (string) - Required - The slug of the sport. - **league** (string) - Optional - The slug of the league. - **status** (string) - Optional - Filter by event status ('upcoming', 'in-play', 'completed'). - **start** (string) - Optional - Start date and time in ISO 8601 format (e.g., '2024-01-15T00:00:00Z'). - **end** (string) - Optional - End date and time in ISO 8601 format (e.g., '2024-01-20T23:59:59Z'). - **bookmaker** (string) - Optional - Filter by bookmaker slug. - **participant_id** (string) - Optional - Filter by participant ID. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: # Get upcoming NBA events events = client.get_events( sport="basketball", league="usa-nba", status="upcoming" ) for event in events[:5]: home = event['home'] away = event['away'] start_time = event['startTime'] print(f"{away} @ {home} - {start_time}") # Get events within a date range events = client.get_events( sport="basketball", start="2024-01-15T00:00:00Z", end="2024-01-20T23:59:59Z" ) print(f"Found {len(events)} events in date range") ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the event. - **sport** (string) - The sport slug. - **league** (string) - The league slug. - **home** (string) - The home team name. - **away** (string) - The away team name. - **startTime** (string) - The start time of the event in ISO 8601 format. - **status** (string) - The status of the event ('upcoming', 'in-play', 'completed'). - **bookmakers** (array) - An array of bookmakers offering odds for the event. - **key** (string) - The bookmaker slug. - **title** (string) - The bookmaker name. - **odds** (array) - An array of odds for different markets. #### Response Example ```json [ { "id": 12345, "sport": "basketball", "league": "usa-nba", "home": "Los Angeles Lakers", "away": "Golden State Warriors", "startTime": "2024-01-15T03:30:00Z", "status": "upcoming", "bookmakers": [ { "key": "bet365", "title": "bet365", "odds": [ { "name": "H2H", "outcomes": [ {"name": "Golden State Warriors", "price": 2.10}, {"name": "Los Angeles Lakers", "price": 1.75} ] } ] } ] } ] ``` ``` -------------------------------- ### Get Participant by ID Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves detailed information for a specific participant by their unique identifier. ```APIDOC ## GET /participants/{participant_id} ### Description Retrieves detailed information for a specific participant by their unique identifier. ### Method GET ### Endpoint /participants/{participant_id} ### Parameters #### Path Parameters - **participant_id** (integer) - Required - The unique identifier of the participant. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: participant = client.get_participant_by_id(participant_id=3428) print(f"Name: {participant.get('name')}") print(f"Sport: {participant.get('sport')}") print(f"League: {participant.get('league')}") ``` ### Response #### Success Response (200) - **participant** (object) - Detailed information about the participant. - **id** (integer) - The unique identifier of the participant. - **name** (string) - The name of the participant. - **sport** (string) - The sport the participant belongs to. - **league** (string) - The league the participant belongs to. #### Response Example ```json { "id": 3428, "name": "Golden State Warriors", "sport": "basketball", "league": "usa-nba" } ``` ``` -------------------------------- ### Get Event Odds Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves current odds for a specific event from specified bookmakers. ```APIDOC ## GET /events/{event_id}/odds ### Description Retrieves current odds for a specific event from specified bookmakers. ### Method GET ### Endpoint /events/{event_id}/odds ### Parameters #### Path Parameters - **event_id** (string) - Required - The unique identifier of the event. #### Query Parameters - **bookmakers** (string) - Optional - A comma-separated list of bookmaker slugs to filter by (e.g., "SingBet,Bet365"). If not provided, odds from all available bookmakers are returned. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: odds = client.get_event_odds( event_id="12345", bookmakers="SingBet,Bet365" ) if 'bookmakers' in odds: for bookie in odds['bookmakers']: print(f"\n{bookie['name']}:") if 'markets' in bookie: for market in bookie['markets']: print(f" {market['name']}:") for outcome in market['outcomes']: print(f" {outcome['name']}: {outcome['price']}") ``` ### Response #### Success Response (200) - **bookmakers** (array) - A list of bookmaker objects, each containing odds for the specified event. - **name** (string) - The name of the bookmaker. - **markets** (array) - A list of market objects for the event. - **name** (string) - The name of the market (e.g., "Moneyline", "Spread"). - **outcomes** (array) - A list of outcome objects for the market. - **name** (string) - The name of the outcome (e.g., "Home", "Away", "Over 2.5"). - **price** (float) - The current odds for the outcome. #### Response Example ```json { "bookmakers": [ { "name": "SingBet", "markets": [ { "name": "Moneyline", "outcomes": [ {"name": "Home", "price": 1.85}, {"name": "Away", "price": 2.05} ] }, { "name": "Spread", "outcomes": [ {"name": "Home -3.5", "price": 1.91}, {"name": "Away +3.5", "price": 1.91} ] } ] } ] } ``` ``` -------------------------------- ### Get Odds for Multiple Events Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Efficiently retrieves odds for multiple events in a single API request. ```APIDOC ## GET /events/odds/batch ### Description Efficiently retrieves odds for multiple events in a single API request. ### Method GET ### Endpoint /events/odds/batch ### Parameters #### Query Parameters - **event_ids** (string) - Required - A comma-separated list of event IDs (e.g., "12345,67890"). - **bookmakers** (string) - Optional - A comma-separated list of bookmaker slugs to filter by. ### Request Example ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: # First get some events events = client.get_events(sport="basketball", league="usa-nba") if len(events) >= 3: event_ids = ",".join(str(e['id']) for e in events[:3]) batch_odds = client.get_odds_for_multiple_events( event_ids=event_ids, bookmakers="SingBet" ) print(f"Fetched odds for {len(batch_odds)} events in one request") ``` ### Response #### Success Response (200) - **events_odds** (array) - A list of objects, where each object contains odds for a specific event. - **event_id** (integer) - The ID of the event. - **bookmakers** (array) - Odds data from specified bookmakers for this event. #### Response Example ```json [ { "event_id": 12345, "bookmakers": [ { "name": "SingBet", "markets": [ { "name": "Moneyline", "outcomes": [ {"name": "Home", "price": 1.85}, {"name": "Away", "price": 2.05} ] } ] } ] } ] ``` ``` -------------------------------- ### Get Odds Movement Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Tracks odds changes over time for a specific event, bookmaker, and market type. ```APIDOC ## GET /events/{event_id}/odds/movement ### Description Tracks odds changes over time for a specific event, bookmaker, and market type. ### Method GET ### Endpoint /events/{event_id}/odds/movement ### Parameters #### Path Parameters - **event_id** (string) - Required - The unique identifier of the event. #### Query Parameters - **bookmaker** (string) - Required - The slug of the bookmaker (e.g., "SingBet"). - **market** (string) - Required - The type of market to track (e.g., "moneyline", "spread"). - **market_line** (string) - Optional - Specific market line if applicable (e.g., "-3.5" for spread). ### Request Example ```python from odds_api import OddsAPIClient from datetime import datetime with OddsAPIClient(api_key="your_api_key") as client: movements = client.get_odds_movement( event_id="12345", bookmaker="SingBet", market="moneyline" ) print(f"Total movements: {len(movements)}") for movement in movements[-5:]: timestamp = movement.get('timestamp') if isinstance(timestamp, int): dt = datetime.fromtimestamp(timestamp) print(f"Time: {dt.strftime('%Y-%m-%d %H:%M:%S')}") if 'odds' in movement: print(f"Odds: {movement['odds']}") print() ``` ### Response #### Success Response (200) - **movements** (array) - A list of historical odds changes for the specified event, bookmaker, and market. - **timestamp** (integer) - Unix timestamp of the odds change. - **odds** (object) - An object containing the odds at the time of the change. #### Response Example ```json [ { "timestamp": 1678886400, "odds": { "Home": 1.80, "Away": 2.10 } } ] ``` ``` -------------------------------- ### Get updated odds since timestamp Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves odds updates since a specific Unix timestamp. Useful for polling for recent changes. ```python from odds_api import OddsAPIClient import time from datetime import datetime with OddsAPIClient(api_key="your_api_key") as client: one_hour_ago = int(time.time()) - 3600 updated_odds = client.get_updated_odds_since_timestamp( since=one_hour_ago, bookmaker="SingBet", sport="basketball" ) print(f"Found {len(updated_odds)} odds updates in the last hour") for update in updated_odds[:5]: if 'event' in update: event = update['event'] print(f"Match: {event['away']} @ {event['home']}") if 'timestamp' in update: dt = datetime.fromtimestamp(update['timestamp']) print(f"Updated: {dt.strftime('%H:%M:%S')}") ``` -------------------------------- ### Get Updated Odds Since Timestamp Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Retrieves odds that have been updated since a specified Unix timestamp, useful for incremental updates. ```APIDOC ## GET /odds/updates ### Description Retrieves odds that have been updated since a specified Unix timestamp, useful for incremental updates. ### Method GET ### Endpoint /odds/updates ### Parameters #### Query Parameters - **since** (integer) - Required - Unix timestamp to retrieve updates from. - **bookmaker** (string) - Optional - Slug of the bookmaker to filter by. - **sport** (string) - Optional - Sport to filter updates by. ### Request Example ```python from odds_api import OddsAPIClient import time from datetime import datetime with OddsAPIClient(api_key="your_api_key") as client: one_hour_ago = int(time.time()) - 3600 updated_odds = client.get_updated_odds_since_timestamp( since=one_hour_ago, bookmaker="SingBet", sport="basketball" ) print(f"Found {len(updated_odds)} odds updates in the last hour") for update in updated_odds[:5]: if 'event' in update: event = update['event'] print(f"Match: {event['away']} @ {event['home']}") if 'timestamp' in update: dt = datetime.fromtimestamp(update['timestamp']) print(f"Updated: {dt.strftime('%H:%M:%S')}") print() ``` ### Response #### Success Response (200) - **updates** (array) - A list of odds update objects. - **event** (object) - Details of the event associated with the odds update. - **timestamp** (integer) - Unix timestamp of when the odds were updated. - **odds** (object) - The updated odds. #### Response Example ```json [ { "event": { "id": 12345, "home": "Team A", "away": "Team B" }, "timestamp": 1678886400, "odds": { "Moneyline": { "Home": 1.90, "Away": 2.00 } } } ] ``` ``` -------------------------------- ### Use Context Managers for Client Management Source: https://github.com/odds-api-io/odds-api-python/blob/main/README.md Demonstrates the recommended way to use both synchronous and asynchronous clients using context managers. This ensures proper resource management. ```python # Sync with OddsAPIClient(api_key="your_api_key") as client: sports = client.get_sports() # Async async with AsyncOddsAPIClient(api_key="your_api_key") as client: sports = await client.get_sports() ``` -------------------------------- ### Client Initialization Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Initialize the synchronous or asynchronous client with your API key. ```APIDOC ## Client Initialization Initialize the synchronous or asynchronous client with your API key to start making requests to the Odds-API.io platform. ```python from odds_api import OddsAPIClient, AsyncOddsAPIClient import os API_KEY = os.getenv("ODDS_API_KEY", "your_api_key_here") # Synchronous client with context manager (recommended) with OddsAPIClient(api_key=API_KEY) as client: sports = client.get_sports() print(f"Found {len(sports)} sports") # Async client with context manager import asyncio async def main(): async with AsyncOddsAPIClient(api_key=API_KEY) as client: sports = await client.get_sports() print(f"Found {len(sports)} sports") asyncio.run(main()) # Manual client management client = OddsAPIClient(api_key=API_KEY, timeout=15) sports = client.get_sports() client.close() ``` ``` -------------------------------- ### Initialize and Use Synchronous OddsAPIClient Source: https://github.com/odds-api-io/odds-api-python/blob/main/README.md Initialize the synchronous client with your API key. Use this client to fetch sports, events, live events, search for games, and find arbitrage opportunities. Remember to close the client when done. ```python from odds_api import OddsAPIClient # Initialize the client client = OddsAPIClient(api_key="your_api_key_here") # Get available sports sports = client.get_sports() print(f"Found {len(sports)} sports") # Get upcoming NBA events events = client.get__events(sport="basketball", league="usa-nba") # Search for specific games lakers_games = client.search_events(query="Lakers") # Get live basketball events live = client.get_live_events(sport="basketball") # Find arbitrage opportunities arb_bets = client.get_arbitrage_bets( bookmakers="singbet,bet365", limit=10, include_event_details=True ) # Close the client when done client.close() ``` -------------------------------- ### Initialize Odds-API Client Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Initialize the synchronous or asynchronous client with your API key. Using a context manager is recommended for proper resource management. ```python from odds_api import OddsAPIClient, AsyncOddsAPIClient import os API_KEY = os.getenv("ODDS_API_KEY", "your_api_key_here") # Synchronous client with context manager (recommended) with OddsAPIClient(api_key=API_KEY) as client: sports = client.get_sports() print(f"Found {len(sports)} sports") # Async client with context manager import asyncio async def main(): async with AsyncOddsAPIClient(api_key=API_KEY) as client: sports = await client.get_sports() print(f"Found {len(sports)} sports") asyncio.run(main()) # Manual client management client = OddsAPIClient(api_key=API_KEY, timeout=15) sports = client.get_sports() client.close() ``` -------------------------------- ### Retrieve Live Events Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Fetch all currently live in-play events for a specific sport. This provides real-time data for ongoing games. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: live_events = client.get_live_events(sport="basketball") if live_events: print(f"Found {len(live_events)} live basketball games") for event in live_events: home = event['home'] away = event['away'] print(f"LIVE: {away} vs {home}") else: print("No live games at the moment") ``` -------------------------------- ### Find Value Betting Opportunities Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Discover value bets with positive expected value based on true probability analysis. Requires a specific bookmaker and optionally includes event details. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: value_bets = client.get_value_bets( bookmaker="SingBet", include_event_details=True ) print(f"Found {len(value_bets)} value betting opportunities") for bet in value_bets[:5]: if 'event' in bet: event = bet['event'] print(f"\nMatch: {event['away']} @ {event['home']}") print(f"Start: {event.get('startTime')}") if 'expectedValue' in bet: print(f"Expected Value: {bet['expectedValue']:.2f}%") if 'outcome' in bet: print(f"Bet on: {bet['outcome']}") if 'odds' in bet: print(f"Odds: {bet['odds']}") if 'impliedProbability' in bet: print(f"Implied Probability: {bet['impliedProbability']:.2f}%") if 'trueProbability' in bet: print(f"True Probability: {bet['trueProbability']:.2f}%") ``` -------------------------------- ### Retrieve Events with Filters Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Fetch events with optional filters for sport, league, status, date range, bookmaker, and participant ID. Useful for finding upcoming games or events within a specific period. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: # Get upcoming NBA events events = client.get_events( sport="basketball", league="usa-nba", status="upcoming" ) for event in events[:5]: home = event['home'] away = event['away'] start_time = event['startTime'] print(f"{away} @ {home} - {start_time}") # Get events within a date range events = client.get_events( sport="basketball", start="2024-01-15T00:00:00Z", end="2024-01-20T23:59:59Z" ) print(f"Found {len(events)} events in date range") ``` -------------------------------- ### Search for events by keyword Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Use this to find events by team or player names. The query parameter supports partial string matching. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: lakers_games = client.search_events(query="Lakers") print(f"Found {len(lakers_games)} Lakers games") for event in lakers_games[:5]: home = event['home'] away = event['away'] print(f"{away} vs {home}") ``` -------------------------------- ### Retrieve Leagues by Sport Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Fetch all leagues for a specific sport. This is useful for filtering events by competition. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: leagues = client.get_leagues(sport="basketball") for league in leagues: print(f"League: {league['name']} (slug: {league['slug']})") ``` -------------------------------- ### Find Arbitrage Betting Opportunities Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Identify arbitrage opportunities across specified bookmakers. Includes event details and profit percentages. Requires bookmakers, limit, and option to include event details. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: arb_bets = client.get_arbitrage_bets( bookmakers="SingBet,Bet365", limit=20, include_event_details=True ) print(f"Found {len(arb_bets)} arbitrage opportunities") for arb in arb_bets[:5]: if 'event' in arb: event = arb['event'] print(f"\nMatch: {event['away']} @ {event['home']}") print(f"Sport: {event['sport']}, League: {event['league']}") if 'profitPercentage' in arb: print(f"Profit: {arb['profitPercentage']:.2f}%") if 'bets' in arb: print("Required bets:") for bet in arb['bets']: print(f" - {bet['outcome']}: {bet['odds']} @ {bet['bookmaker']}") ``` -------------------------------- ### Retrieve participants Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Lists teams or players for a given sport. Supports optional search filtering by name. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: # Get all basketball participants participants = client.get_participants(sport="basketball") print(f"Total participants: {len(participants)}") # Search for specific teams warriors = client.get_participants(sport="basketball", search="Warriors") for team in warriors: print(f"Team: {team['name']}") ``` -------------------------------- ### Async Client Operations Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Enables parallel API requests for improved performance when fetching multiple data sources. ```APIDOC ## Async Client ### Description The `AsyncOddsAPIClient` enables parallel API requests for improved performance when fetching multiple data sources concurrently using `asyncio`. ### Methods - **get_events(sport, league)**: Fetches events for a specific sport and league. - **search_events(query)**: Searches for events based on a team or query string. ``` -------------------------------- ### Retrieve Event by ID Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Fetch detailed information for a specific event using its unique identifier. This provides comprehensive data including participants. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: event = client.get_event_by_id(event_id=12345) print(f"Event ID: {event.get('id')}") print(f"Status: {event.get('status')}") print(f"Home: {event.get('home')}") print(f"Away: {event.get('away')}") if 'participants' in event: print("Participants:") for participant in event['participants']: print(f" - {participant['name']}") ``` -------------------------------- ### Retrieve All Sports Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Fetch all available sports from the Odds-API.io platform. Each sport includes its name and slug. ```python from odds_api import OddsAPIClient with OddsAPIClient(api_key="your_api_key") as client: sports = client.get_sports() for sport in sports: print(f"Sport: {sport['name']} (slug: {sport['slug']})") ``` -------------------------------- ### Handle API Exceptions in Python Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Use specific exception classes to catch and handle different API error states during client requests. The OddsAPIClient should be used within a context manager to ensure proper resource cleanup. ```python from odds_api import ( OddsAPIClient, OddsAPIError, InvalidAPIKeyError, RateLimitExceededError, NotFoundError, ValidationError ) with OddsAPIClient(api_key="your_api_key") as client: try: events = client.get_events(sport="basketball") print(f"Found {len(events)} events") except InvalidAPIKeyError: print("Error: Your API key is invalid. Get one at https://odds-api.io/#pricing") except RateLimitExceededError: print("Error: Rate limit exceeded (5000 requests/hour). Wait before retrying.") except NotFoundError: print("Error: Resource not found. Check your parameters.") except ValidationError as e: print(f"Error: Invalid parameters - {e}") except OddsAPIError as e: print(f"Error: API error - {e}") ``` -------------------------------- ### Async Client for Concurrent Requests Source: https://context7.com/odds-api-io/odds-api-python/llms.txt Utilize the asynchronous client for parallel API requests, enhancing performance when fetching data from multiple sources simultaneously. Supports concurrent fetching of events and searching for events by team. ```python import asyncio from odds_api import AsyncOddsAPIClient async def fetch_multiple_sports_data(): async with AsyncOddsAPIClient(api_key="your_api_key") as client: # Fetch data for multiple sports concurrently basketball, football, tennis = await asyncio.gather( client.get_events(sport="basketball", league="usa-nba"), client.get_events(sport="american-football", league="usa-nfl"), client.get_events(sport="tennis"), ) print(f"Basketball events: {len(basketball)}") print(f"Football events: {len(football)}") print(f"Tennis events: {len(tennis)}") # Search multiple teams concurrently teams = ["Lakers", "Warriors", "Celtics", "Heat"] results = await asyncio.gather( *[client.search_events(query=team) for team in teams] ) for team, events in zip(teams, results): print(f"{team}: {len(events)} games found") asyncio.run(fetch_multiple_sports_data()) ``` -------------------------------- ### Handle Odds API Errors Source: https://github.com/odds-api-io/odds-api-python/blob/main/README.md Demonstrates how to catch specific exceptions like InvalidAPIKeyError, RateLimitExceededError, NotFoundError, ValidationError, and general OddsAPIError when interacting with the API. Ensure you have imported the necessary exception classes. ```python from odds_api import ( OddsAPIClient, OddsAPIError, InvalidAPIKeyError, RateLimitExceededError, NotFoundError, ValidationError ) client = OddsAPIClient(api_key="your_api_key") try: events = client.get_events(sport="basketball") except InvalidAPIKeyError: print("Your API key is invalid") except RateLimitExceededError: print("Rate limit exceeded - wait before retrying") except NotFoundError: print("Resource not found") except ValidationError as e: print(f"Invalid parameters: {e}") except OddsAPIError as e: print(f"API error: {e}") ```