pysbr.queries package¶
Submodules¶
pysbr.queries.bestlines module¶
-
class
pysbr.queries.bestlines.BestLines(event_ids: Union[List[int], int], market_ids: Union[List[int], int])¶ Bases:
pysbr.queries.lines.LinesGet the best lines offered by any sportsbook for a number of events and markets.
For each event, participant and market combination, the best line offered by any of sportsbooks tracked by SBR is in the response. The date and time that the line was offered is also recorded. Both American and decimal odds are included.
Sometimes the best line returned is from a sportsbook that is not active on SBR. In this case you can try searching in the network manager to determine which sportsbook it came from.
- Parameters
event_ids – SBR event id or list of event ids.
market_ids – SBR betting market id or list of market ids.
pysbr.queries.consensusHistory module¶
-
class
pysbr.queries.consensusHistory.ConsensusHistory(event_id: int, market_ids: Union[List[int], int])¶ Bases:
pysbr.queries.lines.LinesGet the consensus amongst SBR members for selected markets on an event.
For events in some leagues and markets, SBR members can simulate a wager on the current line. The query response includes the number of wagers made on a line at a given price, and percentage of wagers made on each side of a bet. For certain markets volume’ and ‘total volume’ are recorded where ‘volume’ refers to the average wager size, and ‘total volume’ is just volume multiplied by the # of wagers. For certain markets the number of whale bets made on a line is available.
Note that the line available for members to make a wager is always from 5Dimes. The markets available for consensus history can be gotten from a league’s config class, if it exists. In general, the 3 available markets are the moneyline, point spread, and total (all full-time).
- Parameters
event_id – SBR event id.
market_ids – SBR betting market ids.
pysbr.queries.currentlines module¶
-
class
pysbr.queries.currentlines.CurrentLines(event_ids: Union[List[int], int], market_ids: Union[List[int], int], sportsbook_ids: Union[List[int], int])¶ Bases:
pysbr.queries.lines.LinesGet the current lines offered by sportsbooks for a number of events and markets.
For each sportsbook, event, participant and market combination, the most recent line offered by the book is in the response. Both American and decimal odds are included.
- Parameters
event_ids – SBR event id or list of event ids.
market_ids – SBR betting market id or list of market ids.
sportsbook_ids – SBR sportsbook id or list of sportsbook ids.
pysbr.queries.eventgroupsbyleague module¶
-
class
pysbr.queries.eventgroupsbyleague.EventGroupsByLeague(league_id: int)¶ Bases:
pysbr.queries.query.QueryGet the event groups available on a particular league.
Event groups refer to things like Week 1 of the NFL season, or the US Open, so you can use this in conjunction with EventsByEventGroups to get information about a group of events. Event group id, name, start date and end date are included in the query response.
- Parameters
league_id – SBR league id.
pysbr.queries.eventmarkets module¶
-
class
pysbr.queries.eventmarkets.EventMarkets(event_id: int)¶ Bases:
pysbr.queries.query.QueryGet the event markets available on a particular event.
The response contains only the market ids, not their names.
- Parameters
event_id – SBR event id.
pysbr.queries.eventsbydate module¶
-
class
pysbr.queries.eventsbydate.EventsByDate(league_ids: Union[List[int], int], dt: datetime.datetime)¶ Bases:
pysbr.queries.query.QueryGet events for selected leagues on a certain date.
All event queries return information about matching events including date and time, location, participants, and associated ids.
- Parameters
league_ids – SBR league id or list of league ids.
dt – Python datetime object representing the date of interest. Events searched are those in the range [dt, dt + 24 hours].
pysbr.queries.eventsbydaterange module¶
-
class
pysbr.queries.eventsbydaterange.EventsByDateRange(league_ids: Union[List[int], int], start: datetime.datetime, end: datetime.datetime)¶ Bases:
pysbr.queries.query.QueryGet events for selected leagues over a range of dates.
All event queries return information about matching events including date and time, location, participants, and associated ids.
- Parameters
league_ids – SBR league id or list of league ids.
start – Python datetime object representing the start date to search.
end – Python datetime object representing the end date to search.
pysbr.queries.eventsbyeventgroup module¶
-
class
pysbr.queries.eventsbyeventgroup.EventsByEventGroup(league_id: int, event_group_id: int, season_id: int, market_id: int)¶ Bases:
pysbr.queries.query.QueryGet events for a particular league and event group.
All event queries return information about matching events including date and time, location, participants, and associated ids.
season_id is a required argument because event group ids are not unique to a season. market_id is a required argument to the query object on the SBR server.
- Parameters
league_id – SBR league id.
event_group_id – SBR event group id.
season_id – SBR season id. The easiest way to find a season id is by making an event query about an event that belongs to the season in question, and getting the season id from that event.
market_id – SBR market id. You can use a league’s config class to get the default market id for a given sport.
pysbr.queries.eventsbyeventids module¶
-
class
pysbr.queries.eventsbyeventids.EventsByEventIds(event_ids: Union[List[int], int])¶ Bases:
pysbr.queries.query.QueryGet events from a list of event ids.
All event queries return information about matching events including date and time, location, participants, and associated ids.
- Parameters
event_ids – SBR event id or list of event ids.
pysbr.queries.eventsbymatchup module¶
-
class
pysbr.queries.eventsbymatchup.EventsByMatchup(participant_id1: int, participant_id2: int, count: int)¶ Bases:
pysbr.queries.query.QueryGet events where two participants matched up against one another.
This query returns up to n previous head-to-head matches between two participants, where n is equal to the count argument. It works with teams or individuals.
Example
EventsByMatchup(1548, 1547, 5) returns from the server the last 5 games between the Seahawks and the 49ers.
All event queries return information about matching events including date and time, location, participants, and associated ids.
- Parameters
participant_id1 – SBR participant id of one of the participants in the matchup. It may refer to a team or an individual.
participant_id2 – SBR participant id of the other participant in the matchup. It may refer to a team or an individual.
count – The max number of events to return, counting in reverse chronological order from present.
pysbr.queries.eventsbyparticipants module¶
-
class
pysbr.queries.eventsbyparticipants.EventsByParticipants(participant_ids: Union[List[int], int], start: datetime.datetime, end: datetime.datetime, league_id: Optional[int] = None, sport_id: Optional[int] = None)¶ Bases:
pysbr.queries.query.QueryGet events for a number of participants over a given date range.
The query returns all events in the date range in which at least one of the participants in the participant id list competed in.
This query makes two requests to the server; one to get all the event and participant ids over the date range, and then another to get the full event information for matching events.
Because of the first query, either a league or sport id must be provided.
All event queries return information about matching events including date and time, location, participants, and associated ids.
- Parameters
participant_ids – SBR participant id or list of participant ids. A participant id may refer to a team or an individual.
start – Python datetime object representing the start date to search.
end – Python datetime object representing the end date to search.
league_id – SBR league id.
sport_id – SBR sport id.
pysbr.queries.eventsbyparticipantsrecent module¶
-
class
pysbr.queries.eventsbyparticipantsrecent.EventsByParticipantsRecent(participant_ids: List[int])¶ Bases:
pysbr.queries.query.QueryGet the 5 most recent events for a number of participants.
5 is an arbitrary number enforced by the query on the server side.
All event queries return information about matching events including date and time, location, participants, and associated ids.
- Parameters
participant_ids – SBR participant id or list of participant ids.
pysbr.queries.leaguehierarchy module¶
-
class
pysbr.queries.leaguehierarchy.LeagueHierarchy(league_id: int)¶ Bases:
pysbr.queries.query.QueryGet the league hierarchy for a particular league.
The query returns a list of dicts, each representing a team in the league. Each dict contains the team id, and information about what conference and division the team belongs to.
Many leagues return an empty list, for example, ATP and many soccer leagues.
- Parameters
league_id – SBR league id.
pysbr.queries.leaguemarkets module¶
-
class
pysbr.queries.leaguemarkets.LeagueMarkets(league_id: int)¶ Bases:
pysbr.queries.query.QueryGet the betting markets available for a particular league.
Only market ids are returned by the query, without market names. For some leagues, this query returns many more market ids than the markets found on SBR.
- Parameters
league_id – SBR league id.
pysbr.queries.leaguesbyleagueids module¶
-
class
pysbr.queries.leaguesbyleagueids.LeaguesByLeagueIds(league_ids: Union[List[int], int])¶ Bases:
pysbr.queries.query.QueryGet information about a number of leagues from their league ids.
League name, abbreviation, and sport id are included in the response.
- Parameters
league_ids – SBR league id or list of league ids.
pysbr.queries.linehistory module¶
-
class
pysbr.queries.linehistory.LineHistory(event_id: int, market_id: int, sportsbook_id: int, participant_ids: Union[List[int], int])¶ Bases:
pysbr.queries.lines.LinesGet the line history of an event and market for a particular sportsbook.
The complete history of line movement for an event, market, and sportsbook is returned by the query. Both American and decimal odds are included.
The query to the server does not work without at least one participant id of a participant in the event. If you only include 1 participant id, the query will only return the history for the side of the bet relevant to that participant id.
- Parameters
event_id – SBR event id.
market_id – SBR betting market id.
sportsbook_id – SBR sportsbook id.
participant_ids – List of participant ids of participants in the event, or just
participant id. (one) –
pysbr.queries.lines module¶
-
class
pysbr.queries.lines.Lines¶ Bases:
pysbr.queries.query.QueryImplements methods particular to queries about betting lines.
This class should not be directly instantiated; use the subclasses defined for each lines-related query.
-
dataframe(events=None) → pandas.core.frame.DataFrame¶ Get a dataframe of elements returned from the query.
If a list of events the lines are for is passed in, extra information about each line will be added to each row of the returned dataframe, including event description, participant information, and betting market name.
-
list(events=None) → List[Dict[str, Union[str, List, Dict]]]¶ Get a list of translated elements returned from the query.
If a list of events the lines are for is passed in, extra information about each line will be added to each element of the returned list, including event description, participant information, and betting market name.
-
pysbr.queries.marketsbymarketids module¶
-
class
pysbr.queries.marketsbymarketids.MarketsByMarketIds(market_ids: List[int], sport_id: int)¶ Bases:
pysbr.queries.query.QueryGet information about a number of leagues from their league ids.
Market name, description, and market type id are included in the response.
- Parameters
market_ids – SBR market id or list of market ids.
sport_id – SBR sport id.
pysbr.queries.openinglines module¶
-
class
pysbr.queries.openinglines.OpeningLines(event_ids: Union[List[int], int], market_ids: Union[List[int], int], sportsbook_id: int)¶ Bases:
pysbr.queries.lines.LinesGet the opening lines offered by a sportsbook for a number of events and markets.
The date and time that the line was offered is also recorded. Both American and decimal odds are included.
- Parameters
event_ids – SBR event id or list of event ids.
market_ids – SBR betting market id or list of market ids.
sportsbook_id – SBR sportsbook id.
pysbr.queries.query module¶
-
class
pysbr.queries.query.Query¶ Bases:
objectBase class for making queries on the SBR GraphQL endpoint.
This class should not be directly instantiated; use the subclasses defined for each query.
-
arguments() → Dict[str, str]¶ Get the arguments dictionary, containing templates for all subqueries.
-
dataframe() → pandas.core.frame.DataFrame¶ Get a dataframe of elements returned from the query.
Each element in the response is a dict with fields requested in the query and the element’s values for those fields. The fields are translated, and if the elements are nested, it is attempted to flatten them using self._sublist_keys, which is a list of keys expected to be in each element that have values that are lists.
If the elements cannot be flattened, a dataframe of the nested elements is returned.
-
fields() → Dict[str, str]¶ Get the fields dictionary, containing templates for all subqueries.
-
id() → Optional[int]¶ Get the first id returned from the query response.
The type of id returned depends on the Query implementation. For example, calling this method on queries returning events will return a list of event ids.
If there are no ids, None is returned.
- Raises
NotImplementedError – If the Query object does not have a default return id type.
-
ids() → List[int]¶ Get a list of ids from the query response.
The type of id returned depends on the Query implementation. For example, calling this method on queries returning events will return a list of event ids.
This method is useful for queries accepting lists of ids as arguments.
- Raises
NotImplementedError – If the Query object does not have a default return id type.
-
list() → List[Dict[str, Union[str, List, Dict]]]¶ Get a list of translated elements returned from the query.
Each element in the response is a dict with fields requested in the query and the element’s values for those fields. The fields are translated.
-
raw() → Dict¶ Get the raw GraphQL response, without any data processing.
-
typecheck() → Callable¶ Decorator for type checking arguments passed to subclass __init__ methods.
The purpose of decorating the subclass __init__ methods is to avoid making invalid queries on the GraphQL endpoint.
This method is only verified to work with List, Union, and primitive types.
- Raises
TypeError – If argument does not match expected type.
-
pysbr.queries.searchevents module¶
-
class
pysbr.queries.searchevents.SearchEvents(search_term: str)¶ Bases:
pysbr.queries.query.QueryGet up to 5 upcoming events matching a given search term.
The search term should be a string referring to a team or participant’s name. Case is ignored. The max number of upcoming events returned is enforced by the server.
This query response has a different structure than other event queries, but still includes information about date and time, participants, description, and associated ids.
- Example search terms:
‘Seattle’ (this will return information about all Seattle-based teams) ‘Seahawks’ ‘Federer’ ‘federer’ ‘roger federer’ ‘tiz the law’ (horse racing)
- Parameters
search_term – String referring to team or participant of interest.
pysbr.queries.searchleagues module¶
-
class
pysbr.queries.searchleagues.SearchLeagues(search_term: str)¶ Bases:
pysbr.queries.query.QueryGet up to 5 leagues matching a given search term.
The search term can be part of a league’s full name or abbreviation. Case is ignored. The max number of results returned is enforced by the server.
The query response includes league name, region, and id, as well as sport id.
- Example search terms:
‘NFL’ ‘National Football League’ ‘National’ ‘nfl’
- Parameters
search_term – String referring to the league of interest.
pysbr.queries.searchsports module¶
-
class
pysbr.queries.searchsports.SearchSports(search_term: str)¶ Bases:
pysbr.queries.query.QueryGet up to 5 sports matching a given search term.
Case is ignored. The max number of upcoming events returned is enforced by the server.
The query response includes sport name and id.
- Parameters
search_term – String referring to the league of interest.
pysbr.queries.sportsbooks module¶
-
class
pysbr.queries.sportsbooks.Sportsbooks(system_sportsbook_ids: Union[List[int], int])¶ Bases:
pysbr.queries.query.QueryGet information about a number of sportsbooks from their system ids.
Note that the id returned from lines-related queries is called ‘sportsbook id’ by this application, which is translated from ‘paid’, the name returned from SBR. There is another sportsbook id that is only used by the ‘Sportsbooks’ query, that is called ‘system sportsbook id’ by this application, which is translated from ‘sbid’, the name returned from SBR. The system sportsbook id is not used by other parts of the application.
Sportsbook name, id (paid), and system id (sbid) are included in the response.
- Parameters
system_sportsbook_ids – The system ids of the sportsbooks of interest.
pysbr.queries.team module¶
-
class
pysbr.queries.team.Team(team_id: int)¶ Bases:
pysbr.queries.query.QueryGet information about a team from its team id.
The team’s name, location, conference, division, league, and associated ids are among the values returned from the query.
- Parameters
team_id – SBR team id.