Package: draftfast
Introduction ··An incredibly powerful tool that automates and optimizes lineup building, allowing you to enter thousands of lineups in any DraftKings or FanDuel contest in the time it takes you to grab a coffee.InstallationRequires Python 3.12+.pipinstalldraftfastUsageExample usage (you can experiment with these examples in repl.it):fromdraftfastimportrulesfromdraftfast.optimizeimportrunfromdraftfast.ormimportPlayerfromdraftfast.csv_parseimportsalary_download# Create players for a classic DraftKings gameplayer_pool=[Player(name='A1',cost=5500,proj=55,pos='PG'),Player(name='A2',cost=5500,proj=55,pos='PG'),Player(name='A3',cost=5500,proj=55,pos='SG'),Player(name='A4',cost=5500,proj=55,pos='SG'),Player(name='A5',cost=5500,proj=55,pos='SF'),Player(name='A6',cost=5500,proj=55,pos='SF'),Player(name='A7',cost=5500,proj=55,pos='PF'),Player(name='A8',cost=5500,proj=55,pos='PF'),Player(name='A9',cost=5500,proj=55,pos='C'),Player(name='A10',cost=5500,proj=55,pos='C'),]roster=run(rule_set=rules.DK_NBA_RULE_SET,player_pool=player_pool,verbose=True,)# Or, alternatively, generate players from a CSVplayers=salary_download.generate_players_from_csvs(salary_file_location='./salaries.csv',game=rules.DRAFT_KINGS,)roster=run(rule_set=rules.DK_NBA_RULE_SET,player_pool=players,verbose=True,)You can see more examples in theexamplesdirectory.Game RulesOptimizing for a particular game is as easy as setting theRuleSet(see the example above). Game rules in the library are in the table below:LeagueSiteReferenceNFLDraftKingsDK_NFL_RULE_SETNFLFanDuelFD_NFL_RULE_SETNBADraftKingsDK_NBA_RULE_SETNBAFanDuelFD_NBA_RULE_SETMLBDraftKingsDK_MLB_RULE_SETMLBFanDuelFD_MLB_RULE_SETWNBADraftKingsDK_WNBA_RULE_SETWNBAFanDuelFD_WNBA_RULE_SETPGAFanDuelFD_PGA_RULE_SETPGADraftKingsDK_PGA_RULE_SETPGA_CAPTAINDraftKingsDK_PGA_CAPTAIN_RULE_SETNASCARFanDuelFD_NASCAR_RULE_SETNASCARDraftKingsDK_NASCAR_RULE_SETSOCCERDraftKingsDK_SOCCER_RULE_SETEuroLeagueDraftKingsDK_EURO_LEAGUE_RULE_SETNHLDraftKingsDK_NHL_RULE_SETNBA PickemDraftKingsDK_NBA_PICKEM_RULE_SETNFL ShowdownDraftKingsDK_NFL_SHOWDOWN_RULE_SETNBA ShowdownDraftKingsDK_NBA_SHOWDOWN_RULE_SETMLB ShowdownDraftKingsDK_MLB_SHOWDOWN_RULE_SETXFLDraftKingsDK_XFL_CLASSIC_RULE_SETTennisDraftKingsDK_TEN_CLASSIC_RULE_SETCS:GODraftKingsDK_CSGO_SHOWDOWNF1DraftKingsDK_F1_SHOWDOWNNFL MVPFanDuelFD_NFL_MVP_RULE_SETMLB MVPFanDuelFD_MLB_MVP_RULE_SETNBA MVPFanDuelFD_NBA_MVP_RULE_SETNote that you can also tunedraftfastfor any game of your choice even if it's not implemented in the library (PRs welcome!). Using theRuleSetclass, you can generate your own game rules that specific number of players, salary, etc. Example:fromdraftfastimportrulesgolf_rules=rules.RuleSet(site=rules.DRAFT_KINGS,league='PGA',roster_size='6',position_limits=[['G',6,6]],salary_max=50_000,)SettingsUsage example:classShowdown(Roster):POSITION_ORDER={'M':0,'F':1,'D':2,'GK':3,}showdown_limits=[['M',0,6],['F',0,6],['D',0,6],['GK',0,6],]soccer_rules=rules.RuleSet(site=rules.DRAFT_KINGS,league='SOCCER_SHOWDOWN',roster_size=6,position_limits=showdown_limits,salary_max=50_000,general_position_limits=[],)player_pool=salary_download.generate_players_from_csvs(salary_file_location=salary_file,game=rules.DRAFT_KINGS,)roster=run(rule_set=soccer_rules,player_pool=player_pool,verbose=True,roster_gen=Showdown,)PlayerPoolSettingsmin_projmax_projmin_salarymax_salarymin_avgmax_avgOptimizerSettingsstacks- A list ofStackobjects. Example:roster=run(rule_set=rules.DK_NHL_RULE_SET,player_pool=player_pool,verbose=True,optimizer_settings=OptimizerSettings(stacks=[Stack(team='PHI',count=3),Stack(team='FLA',count=3),Stack(team='NSH',count=2),]),)Stackcan also be tuned to support different combinations of positions. For NFL,
to only specify a QB-WRs based stack of five:Stack(team='NE',count=5,stack_lock_pos=['QB'],stack_eligible_pos=['WR'],)custom_rules- Define rules that set if / then conditions for lineups.For example, if two WRs from the same team are in a naturally optimized lineup, then the QB must also be in the lineup. You can find some good examples of rules indraftfast/test/test_custom_rules.py.fromdraftfast.optimizeimportrunfromdraftfast.settingsimportOptimizerSettings,CustomRule# If two WRs on one team, play the QB from same teamsettings=OptimizerSettings(custom_rules=[CustomRule(group_a=lambdap:p.pos=='WR'andp.team=='Patriots',group_b=lambdap:p.pos=='QB'andp.team=='Patriots',comparison=lambdasum,a,b:sum(a)+1<=sum(b))])roster=run(rule_set=rules.DK_NFL_RULE_SET,player_pool=nfl_pool,verbose=True,optimizer_settings=settings,)Another common use case is given one player is in a lineup, always play another player:fromdraftfast.optimizeimportrunfromdraftfast.settingsimportOptimizerSettings,CustomRule# If Player A, always play Player B and vice versasettings=OptimizerSettings(custom_rules=[CustomRule(group_a=lambdap:p.name=='Tom Brady',group_b=lambdap:p.name=='Rob Gronkowski',comparison=lambdasum,a,b:sum(a)==sum(b))])roster=run(rule_set=rules.DK_NFL_RULE_SET,player_pool=nfl_pool,verbose=True,optimizer_settings=settings,)Custom rules also don't have to make a comparison between two groups. You can say "never play these two players in the same lineup" by using theCustomRule#comparisonproperty.# Never play these two players togethersettings=OptimizerSettings(custom_rules=[CustomRule(group_a=lambdap:p,group_b=lambdap:p.name=='Devon Booker'orp.name=='Chris Paul',comparison=lambdasum,a,b:sum(b)<=1)])roster=run(rule_set=rules.DK_NBA_RULE_SET,player_pool=nba_pool,verbose=True,optimizer_settings=settings,)Importantly, as of this writing, passing closures intoCustomRules does not work (ex.lambda p: p.team == team),
so dynamically generating rules is not possible. PRs welcome for a fix here, I believe this is a limitation ofortools.LineupConstraintslocked- list of players to lockbanned- list of players to bangroups- list of player groups constraints. See belowroster=run(rule_set=rules.DK_NFL_RULE_SET,player_pool=player_pool,verbose=True,constraints=LineupConstraints(locked=['Rob Gronkowski'],banned=['Mark Ingram','Doug Martin'],groups=[[('Todd Gurley','Melvin Gordon','Christian McCaffrey'),(2,3)],[('Chris Carson','Mike Davis'),1],]))no_offense_against_defense- Do not allow offensive players to be matched up against defensive players in the optimized lineup. Currently only implemented for soccer, NHL, and NFL -- PRs welcome!CSV Uploadfromdraftfast.csv_parseimportuploadersuploader=uploaders.DraftKingsNBAUploader(pid_file='./pid_file.csv',)uploader.write_rosters(rosters)Support and ConsultingDFS optimization is only one part of a sustainable strategy. Long-term DFS winners have the best:Player projectionsBankroll managementDiversification in contests playedDiversification across lineups (seedraftfast.exposure)Research process1 hour before gametime lineup changes...and so much moreDraftFast provides support and consulting services that can help with all of these.Let's get in touch today.ContributingRun tests or set of tests:# All testsnose2# Single filenose2draftfast.test.test_soccer# Single testnosetestsdraftfast.test.test_soccer.test_soccer_dk_no_opp_dRun lintingflake8 draftfastCreditsSpecial thanks toswanson, who authoredthis repo, which was the inspiration for this one.Current project maintainers:BenBrostoffsharkiteuthis