Package: python-sbr
PySBRA Python client for accessing the Sportsbook Review GraphQL endpoint.This library allows you to get odds and other information fromSportsbook Review(SBR) for any of the leagues that are supported on the website, including NFL, NCAAB, UFC, ATP, EPL and many others. For a given event, you can get the current, best, opening lines and line history for any combination of betting markets and sportsbooks available on the website.The SBR GraphQL endpoint is undocumented and subject to change, so use at your own risk. Try and avoid getting rate limited so we can keep this available for everyone to use!Project documentation found onReadTheDocsThere is also adiscord channelset up for this project that may be helpful.Installationpipinstallpython-sbrExamplesfrompysbrimport*fromdatetimeimportdatetimeCurrent lines for Sunday's NFL gamesdt=datetime.strptime('2020-12-06','%Y-%m-%d')nfl=NFL()sb=Sportsbook()NFLandSportsbookare examples of config classes that are provided so you don't need to remember various interal IDs, such as team, league, sport, sportsbook, or betting market ids. The full list of config classes can be found in the documentation.Using theNFLconfig class to get the NFL's league id, theEventsByDatequery can then be used to retrieve all the events on some date for a given league or sport.e=EventsByDate(nfl.league_id,dt)All queries havelistanddataframeas available instance methods, producing a readable and formatted list or dataframe of the server response. You can also view the raw response from the server by accessing the_rawinstance variable.e.list()[0]{'scores':[],'sport id':4,'league id':16,'season id':8582,'event id':4143414,'description':'Jacksonville Jaguars@Minnesota Vikings','location':'Minneapolis','country':'USA','event status':'scheduled','datetime':'2020-12-06T10:00:00-08:00','stadium type':'artificial','participants':[{'participant id':1529,'is home':False,'source':{'name':'Jacksonville','nickname':'Jaguars','short name':'Jacksonville','abbreviation':'JAC','location':'Jacksonville'}},{'participant id':1541,'is home':True,'source':{'name':'Minnesota','nickname':'Vikings','short name':'Minnesota','abbreviation':'MIN','location':'Minnesota'}}],'event group':{'event group id':22,'name':'REG Week 13','alias':'Week 13'}}Then you can get the current lines for any betting markets and sportsbooks of interest by usingCurrentLines.cl=CurrentLines(e.ids(),nfl.market_ids(['1Qou','ps','1st half moneyline']),sb.ids(['Pinnacle','Bovada']))Notice how you can use theNFLconfig class to find the betting market ids for 1st quarter over/under, full game point spread, and 1st half moneyline. See the documentation for accepted formats. Similarly, you can useSportsbookto find sportsbook ids.cl.list(e)[0]{'market id':91,'event id':4143414,'sportsbook id':20,'datetime':'2020-12-05T07:26:01-08:00','participant id':1529,'spread / total':0,'decimal odds':3.56,'american odds':256,'event':'Jacksonville Jaguars@Minnesota Vikings','market':'1st Half - Draw No Bet','sportsbook':'Pinnacle','participant':'JAC'}In order to get the 'event', 'market', 'sportsbook' and 'participant' fields, pass the event object intolistordataframefor any lines-related query.If an event is already completed, 'scores' will be populated in the response. The score data can then be used to calculate the result of the bet.dt=datetime.strptime('2020-11-30','%Y-%m-%d')e=EventsByDate(nfl.league_id,dt)cl=CurrentLines(e.ids(),nfl.market_ids(['1Qou','ps','1st half moneyline']),sb.ids(['Pinnacle','Bovada']))cl.list(e)[:2][{'market id':91,'event id':4143550,'sportsbook id':20,'datetime':'2020-11-30T17:12:25-08:00','participant id':1536,'spread / total':0,'decimal odds':2.7,'american odds':170,'event':'Seattle Seahawks@Philadelphia Eagles','market':'1st Half - Draw No Bet','result':'L','profit':-100.0,'participant score':17,'sportsbook':'Pinnacle','participant':'PHI'},{'market id':91,'event id':4143550,'sportsbook id':20,'datetime':'2020-11-30T17:12:25-08:00','participant id':1548,'spread / total':0,'decimal odds':1.5128,'american odds':-195,'event':'Seattle Seahawks@Philadelphia Eagles','market':'1st Half - Draw No Bet','result':'W','profit':51.28,'participant score':23,'sportsbook':'Pinnacle','participant':'SEA'}]You can see that Seahawks won the 1st half by a score of 23-17, netting a profit of $51.28 on a $100 bet on Seahawks 1st half ML if you were to bet Pinnacle's closing line.Opening lines for teams over date rangencaab=NCAAB()sb=Sportsbook()start=datetime.strptime('2020-11-25','%Y-%m-%d')end=datetime.strptime('2020-12-03','%Y-%m-%d')For NCAA basketball all the teams have been added to the config class, so here you can use theteam_idsmethod.gonzaga=ncaab.team_id("GONZ")baylor=ncaab.team_id("baylor")EventsByParticipantsincludes any games that Gonzaga or Baylor played in over the given date range.e=EventsByParticipants([gonzaga,baylor],start,end,ncaab.league_id)Use theOpeningLinesquery to get the opening lines on Bovada for all the matching games:ol=OpeningLines(e.ids(),ncaab.market_id('ps'),sb.id('Bovada'))ol.list(e)[1]{'market id':401,'event id':4285569,'sportsbook id':9,'datetime':'2020-11-23T17:55:49-08:00','participant id':651,'spread / total':-4,'decimal odds':1.9091,'american odds':-110,'event':'Gonzaga Bulldogs@Kansas Jayhawks','market':'Point Spread (Including OT)','result':'W','profit':90.91,'participant score':102,'sportsbook':'Bovada','participant':'GONZ'}ol.list(e)[5]{'market id':401,'event id':4286230,'sportsbook id':9,'datetime':'2020-12-01T15:10:19-08:00','participant id':687,'spread / total':-5.5,'decimal odds':1.9091,'american odds':-110,'event':'Illinois Fighting Illini@Baylor Bears','market':'Point Spread (Including OT)','result':'W','profit':90.91,'participant score':82,'sportsbook':'Bovada','participant':'BAY'}Gonzaga opened as a 4 point favorite against Kansas, and Baylor opened as a 5.5 point favorite against Illinois.Search for event and get line historyufc=UFC()sb=Sportsbook()For some leagues there is no configuration class, or it doesn't have teams or participants. In this caseSearchEventscomes in handy. You can search for an upcoming event by participant like so:s=SearchEvents('vettori')s.list()[0]{'description':'Jack Hermansson@Marvin Vettori','datetime':'2020-12-05T20:59:00-08:00','league':'UFC','sport':'fighting','sport id':9,'event id':4293126,'participants':[{'psid':66013,'rot':24149,'event id':4293126,'participant id':66013,'is home':False,'source':{'team id':66013,'league id':26,'name':'Jack Hermansson','nickname':None,'short name':None,'abbreviation':None},'name':'Jack Hermansson'},{'psid':66261,'rot':24150,'event id':4293126,'participant id':66261,'is home':True,'source':{'team id':66261,'league id':26,'name':'Marvin Vettori','nickname':None,'short name':None,'abbreviation':None},'name':'Marvin Vettori'}],'league id':26}You can get the complete line movement history for an event for a given market and sportsbook. Here you can see the line moving in Vettori's favor.vettori=s.list()[0]['participants'][1]['participant id']lh=LineHistory(s.id(),ufc.default_market_id,sb.id('Pinnacle'),vettori)lh.list(s)[0]{'market id':126,'event id':4293126,'sportsbook id':20,'datetime':'2020-12-05T20:27:03-08:00','participant id':66261,'spread / total':0,'decimal odds':1.6944,'american odds':-144,'event':'Jack Hermansson@Marvin Vettori','market':'2way','sportsbook':'Pinnacle','participant':'Marvin Vettori'}lh.list(s)[1]{'market id':126,'event id':4293126,'sportsbook id':20,'datetime':'2020-12-05T20:20:20-08:00','participant id':66261,'spread / total':0,'decimal odds':1.7092,'american odds':-141,'event':'Jack Hermansson@Marvin Vettori','market':'2way','sportsbook':'Pinnacle','participant':'Marvin Vettori'}Getting odds on Wimbledon futuressb=Sportsbook()atp=ATP()Sometimes it may not be obvious how to find a given market id. In this case you can callsport_configon a league configuration class and search for the market you are looking for. See the documentation for other config methods.print(atp.sport_config()){'default market id':126,'consensus market ids':[126,395,396],'markets':[{'periods':0,'alias':'','market types':[{'alias':'Money Lines','market id':126,'name':'2way','url':'money-line'},{'alias':'Point Spreads','market id':395,'name':'Point Spread','url':'pointspread'},{'alias':'Total Games','market id':396,'name':'American Total','url':'totals'}],'market group id':217,'name':'Full Game','url':'full-game'},{'alias':'Futures','market types':[{'alias':'French Open Winner','market id':719,'name':'French Open Winner','url':'french-open-winner'},{'alias':'Wimbledon Winner','market id':720,'name':'Wimbledon Winner','url':'davis-cup-winner'},{'alias':'US Open Winner','market id':721,'name':'US Open Winner','url':'us-open-winner'},{'alias':'Australian Open Winner','market id':723,'name':'Australian Open Winner','url':'australian-open-winner'}],'market group id':224,'name':'Futures','url':'futures'}],'sport id':8}wimbledon_futures_id=720start=datetime.strptime('2021-06-28','%Y-%m-%d')end=datetime.strptime('2021-07-12','%Y-%m-%d')You can useEventsByDateRangeto find Wimbledon's event id.e=EventsByDateRange(atp.league_id,start,end)wimbledon_eid=e.list()[0]['event id']With Wimbledon's event id and the futures market id, you can get the current odds on Bet365 for each competitor to win Wimbledon.cl=CurrentLines(wimbledon_eid,wimbledon_futures_id,sb.id('bet365'))[oforoincl.list(e)ifo['participant']in['Dimitrov','Djokovic','Nadal']][{'market id':720,'event id':4138561,'sportsbook id':5,'datetime':'2020-04-04T10:46:32-07:00','participant id':5371,'spread / total':0,'decimal odds':67,'american odds':6600,'event':'2021 Wimbledon Winner ATP','market':'Wimbledon Winner','sportsbook':'Bet365','participant':'Dimitrov'},{'market id':720,'event id':4138561,'sportsbook id':5,'datetime':'2020-04-04T10:46:32-07:00','participant id':5373,'spread / total':0,'decimal odds':2.5,'american odds':150,'event':'2021 Wimbledon Winner ATP','market':'Wimbledon Winner','sportsbook':'Bet365','participant':'Djokovic'},{'market id':720,'event id':4138561,'sportsbook id':5,'datetime':'2020-04-04T10:46:32-07:00','participant id':5684,'spread / total':0,'decimal odds':8,'american odds':700,'event':'2021 Wimbledon Winner ATP','market':'Wimbledon Winner','sportsbook':'Bet365','participant':'Nadal'}]Development setupUse Pipenv. Clone this repo, and then runpipenv install --dev --pre blackto create a virtual environment with dev dependencies installed.To run the test suite:pipenvrunpytest--cov=pysbrtests/Insideconftest.pythere are 3 global variables,QUERY_SERVER,WAIT_MEANandWAIT_DEVIATIONthat you can change to actually query the SBR server when testing, otherwise the test suite willnotquery the server, it will use the saved cassettes.Release History0.3.2FIX: Add fake-useragent to install-requires0.3.1FIX: HTTP error 4630.3.0ADD: 'participant full name' and 'sportsbook alias' keys on lines lists / dataframesADD: New league config classes0.2.1CHANGE: Update README0.2.0FIX: LineHistory bugADD: id methods for Query and Config classes0.1.3CHANGE: Update docs0.1.0Initial releaseMetaJeremy Morrison –jeremymorrison.ca-contact@jeremymorrison.caDistributed under the MIT license. SeeLICENSEfor more information.github.com/JeMorriso/PySBRContributingFork it (https://github.com/JeMorriso/PySBR/fork)Create your feature branch (git checkout -b feature/fooBar)Commit your changes (git commit -am 'Add some fooBar')Push to the branch (git push origin feature/fooBar)Create a new Pull Request