{"id":25491529,"url":"https://github.com/benbrostoff/draftfast","last_synced_at":"2025-04-12T19:48:55.897Z","repository":{"id":36383856,"uuid":"40688731","full_name":"BenBrostoff/draftfast","owner":"BenBrostoff","description":"A tool to automate and optimize DraftKings and FanDuel lineup construction.","archived":false,"fork":false,"pushed_at":"2024-01-29T13:42:15.000Z","size":2189,"stargazers_count":289,"open_issues_count":25,"forks_count":115,"subscribers_count":33,"default_branch":"master","last_synced_at":"2025-04-12T19:48:51.133Z","etag":null,"topics":["dfs","draftkings","lineup-uploads","nba","nfl","optimizer","pickem","python-3","wnba"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BenBrostoff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-14T01:00:56.000Z","updated_at":"2025-04-10T08:56:31.000Z","dependencies_parsed_at":"2025-02-25T23:00:29.709Z","dependency_job_id":"27d9a34c-850f-44b7-891c-d45803d5711e","html_url":"https://github.com/BenBrostoff/draftfast","commit_stats":{"total_commits":606,"total_committers":11,"mean_commits":55.09090909090909,"dds":"0.20132013201320131","last_synced_commit":"f23ab5eb8137410764bd61d98e4f8a718b8a534e"},"previous_names":[],"tags_count":91,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenBrostoff%2Fdraftfast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenBrostoff%2Fdraftfast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenBrostoff%2Fdraftfast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenBrostoff%2Fdraftfast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenBrostoff","download_url":"https://codeload.github.com/BenBrostoff/draftfast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625501,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dfs","draftkings","lineup-uploads","nba","nfl","optimizer","pickem","python-3","wnba"],"created_at":"2025-02-18T22:17:53.069Z","updated_at":"2025-04-12T19:48:55.876Z","avatar_url":"https://github.com/BenBrostoff.png","language":"Python","readme":"## Introduction \u0026middot; [![Build status](https://github.com/BenBrostoff/draftfast/actions/workflows/main.yml/badge.svg)](https://github.com/BenBrostoff/draftfast/actions/workflows/main.yml)  \u0026middot; [![](https://draftfast.herokuapp.com/badge.svg)](https://draftfast.herokuapp.com/)\n\n![](marketing/MAIN_WORKFLOW.png)\n![](marketing/USE_CASES.png)\n\nAn 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.\n\n## Installation\n\nRequires Python 3.12+.\n\n```bash\npip install draftfast\n```\n\n## Usage\n\nExample usage ([you can experiment with these examples in repl.it](https://repl.it/@BenBrostoff/AllWarlikeDemoware)):\n\n```python\nfrom draftfast import rules\nfrom draftfast.optimize import run\nfrom draftfast.orm import Player\nfrom draftfast.csv_parse import salary_download\n\n# Create players for a classic DraftKings game\nplayer_pool = [\n    Player(name='A1', cost=5500, proj=55, pos='PG'),\n    Player(name='A2', cost=5500, proj=55, pos='PG'),\n    Player(name='A3', cost=5500, proj=55, pos='SG'),\n    Player(name='A4', cost=5500, proj=55, pos='SG'),\n    Player(name='A5', cost=5500, proj=55, pos='SF'),\n    Player(name='A6', cost=5500, proj=55, pos='SF'),\n    Player(name='A7', cost=5500, proj=55, pos='PF'),\n    Player(name='A8', cost=5500, proj=55, pos='PF'),\n    Player(name='A9', cost=5500, proj=55, pos='C'),\n    Player(name='A10', cost=5500, proj=55, pos='C'),\n]\n\nroster = run(\n    rule_set=rules.DK_NBA_RULE_SET,\n    player_pool=player_pool,\n    verbose=True,\n)\n\n# Or, alternatively, generate players from a CSV\nplayers = salary_download.generate_players_from_csvs(\n  salary_file_location='./salaries.csv',\n  game=rules.DRAFT_KINGS,\n)\n\nroster = run(\n  rule_set=rules.DK_NBA_RULE_SET,\n  player_pool=players,\n  verbose=True,\n)\n```\n\nYou can see more examples in the [`examples` directory](https://github.com/BenBrostoff/draftfast/tree/master/examples).\n\n## Game Rules\n\nOptimizing for a particular game is as easy as setting the `RuleSet` (see the example above). Game rules in the library are in the table below:\n\n| League       | Site           | Reference  |\n| ------------- |:-------------:| :-----:|\n| NFL | DraftKings | `DK_NFL_RULE_SET` |\n| NFL | FanDuel | `FD_NFL_RULE_SET` |\n| NBA | DraftKings | `DK_NBA_RULE_SET` |\n| NBA | FanDuel | `FD_NBA_RULE_SET` |\n| MLB | DraftKings | `DK_MLB_RULE_SET` |\n| MLB | FanDuel | `FD_MLB_RULE_SET` |\n| WNBA | DraftKings | `DK_WNBA_RULE_SET` |\n| WNBA | FanDuel | `FD_WNBA_RULE_SET` |\n| PGA | FanDuel | `FD_PGA_RULE_SET` |\n| PGA | DraftKings | `DK_PGA_RULE_SET` |\n| PGA_CAPTAIN | DraftKings | `DK_PGA_CAPTAIN_RULE_SET` |\n| NASCAR | FanDuel | `FD_NASCAR_RULE_SET` |\n| NASCAR | DraftKings | `DK_NASCAR_RULE_SET` |\n| SOCCER | DraftKings | `DK_SOCCER_RULE_SET` |\n| EuroLeague | DraftKings | `DK_EURO_LEAGUE_RULE_SET` |\n| NHL | DraftKings | `DK_NHL_RULE_SET` |\n| NBA Pickem | DraftKings | `DK_NBA_PICKEM_RULE_SET` |\n| NFL Showdown | DraftKings | `DK_NFL_SHOWDOWN_RULE_SET` |\n| NBA Showdown | DraftKings | `DK_NBA_SHOWDOWN_RULE_SET` |\n| MLB Showdown | DraftKings | `DK_MLB_SHOWDOWN_RULE_SET` |\n| XFL | DraftKings | `DK_XFL_CLASSIC_RULE_SET` |\n| Tennis | DraftKings | `DK_TEN_CLASSIC_RULE_SET` |\n| CS:GO | DraftKings | `DK_CSGO_SHOWDOWN` |\n| F1 | DraftKings | `DK_F1_SHOWDOWN` |\n| NFL MVP | FanDuel | `FD_NFL_MVP_RULE_SET` |\n| MLB MVP | FanDuel | `FD_MLB_MVP_RULE_SET` |\n| NBA MVP | FanDuel | `FD_NBA_MVP_RULE_SET` |\n\nNote that you can also tune `draftfast` for any game of your choice even if it's not implemented in the library (PRs welcome!). Using the `RuleSet` class, you can generate your own game rules that specific number of players, salary, etc. Example:\n\n```python\nfrom draftfast import rules\n\ngolf_rules = rules.RuleSet(\n    site=rules.DRAFT_KINGS,\n    league='PGA',\n    roster_size='6',\n    position_limits=[['G', 6, 6]],\n    salary_max=50_000,\n)\n```\n\n## Settings\n\nUsage example:\n\n```python\nclass Showdown(Roster):\n    POSITION_ORDER = {\n        'M': 0,\n        'F': 1,\n        'D': 2,\n        'GK': 3,\n    }\n\n\nshowdown_limits = [\n    ['M', 0, 6],\n    ['F', 0, 6],\n    ['D', 0, 6],\n    ['GK', 0, 6],\n]\n\nsoccer_rules = rules.RuleSet(\n    site=rules.DRAFT_KINGS,\n    league='SOCCER_SHOWDOWN',\n    roster_size=6,\n    position_limits=showdown_limits,\n    salary_max=50_000,\n    general_position_limits=[],\n)\nplayer_pool = salary_download.generate_players_from_csvs(\n    salary_file_location=salary_file,\n    game=rules.DRAFT_KINGS,\n)\nroster = run(\n    rule_set=soccer_rules,\n    player_pool=player_pool,\n    verbose=True,\n    roster_gen=Showdown,\n)\n```\n\n`PlayerPoolSettings`\n\n- `min_proj`\n- `max_proj`\n- `min_salary`\n- `max_salary`\n- `min_avg`\n- `max_avg`\n\n`OptimizerSettings`\n\n- `stacks` - A list of `Stack` objects. Example:\n\n```python\nroster = run(\n    rule_set=rules.DK_NHL_RULE_SET,\n    player_pool=player_pool,\n    verbose=True,\n    optimizer_settings=OptimizerSettings(\n        stacks=[\n            Stack(team='PHI', count=3),\n            Stack(team='FLA', count=3),\n            Stack(team='NSH', count=2),\n        ]\n    ),\n)\n```\n\n`Stack` can also be tuned to support different combinations of positions. For NFL,\nto only specify a QB-WRs based stack of five:\n\n```python\nStack(\n    team='NE',\n    count=5,\n    stack_lock_pos=['QB'],\n    stack_eligible_pos=['WR'],\n)\n```\n\n- `custom_rules` - Define rules that set if / then conditions for lineups.\n\n\nFor 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 in `draftfast/test/test_custom_rules.py`.\n\n```python\nfrom draftfast.optimize import run\nfrom draftfast.settings import OptimizerSettings, CustomRule\n\n# If two WRs on one team, play the QB from same team\nsettings = OptimizerSettings(\n    custom_rules=[\n        CustomRule(\n            group_a=lambda p: p.pos == 'WR' and p.team == 'Patriots',\n            group_b=lambda p: p.pos == 'QB' and p.team == 'Patriots',\n            comparison=lambda sum, a, b: sum(a) + 1 \u003c= sum(b)\n        )\n    ]\n)\nroster = run(\n    rule_set=rules.DK_NFL_RULE_SET,\n    player_pool=nfl_pool,\n    verbose=True,\n    optimizer_settings=settings,\n)\n```\n\nAnother common use case is given one player is in a lineup, always play another player:\n\n```python\nfrom draftfast.optimize import run\nfrom draftfast.settings import OptimizerSettings, CustomRule\n\n# If Player A, always play Player B and vice versa\nsettings = OptimizerSettings(\n    custom_rules=[\n        CustomRule(\n            group_a=lambda p: p.name == 'Tom Brady',\n            group_b=lambda p: p.name == 'Rob Gronkowski',\n            comparison=lambda sum, a, b: sum(a) == sum(b)\n        )\n    ]\n)\nroster = run(\n    rule_set=rules.DK_NFL_RULE_SET,\n    player_pool=nfl_pool,\n    verbose=True,\n    optimizer_settings=settings,\n)\n```\n\nCustom 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 the `CustomRule#comparison` property.\n\n```python\n# Never play these two players together\nsettings = OptimizerSettings(\n    custom_rules=[\n        CustomRule(\n            group_a=lambda p: p,\n            group_b=lambda p: p.name == 'Devon Booker' or p.name == 'Chris Paul',\n            comparison=lambda sum, a, b: sum(b) \u003c= 1\n        )\n    ]\n)\nroster = run(\n    rule_set=rules.DK_NBA_RULE_SET,\n    player_pool=nba_pool,\n    verbose=True,\n    optimizer_settings=settings,\n)\n```\n\nImportantly, as of this writing, passing closures into `CustomRule`s does not work (ex. `lambda p: p.team == team`),\nso dynamically generating rules is not possible. PRs welcome for a fix here, I believe this is a limitation of `ortools`.\n\n`LineupConstraints`\n\n- `locked` - list of players to lock\n- `banned` - list of players to ban\n- `groups` - list of player groups constraints. See below\n\n```python\nroster = run(\n    rule_set=rules.DK_NFL_RULE_SET,\n    player_pool=player_pool,\n    verbose=True,\n    constraints=LineupConstraints(\n        locked=['Rob Gronkowski'],\n        banned=['Mark Ingram', 'Doug Martin'],\n        groups=[\n            [('Todd Gurley', 'Melvin Gordon', 'Christian McCaffrey'), (2, 3)],\n            [('Chris Carson', 'Mike Davis'), 1],\n        ]\n    )\n)\n```\n\n- `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!\n\n## CSV Upload\n\n```python\nfrom draftfast.csv_parse import uploaders\n\nuploader = uploaders.DraftKingsNBAUploader(\n    pid_file='./pid_file.csv',\n)\nuploader.write_rosters(rosters)\n\n```\n\n## Support and Consulting\n\nDFS optimization is only one part of a sustainable strategy. Long-term DFS winners have the best:\n\n- Player projections\n- Bankroll management\n- Diversification in contests played\n- Diversification across lineups (see `draftfast.exposure`)\n- Research process\n- 1 hour before gametime lineup changes\n- ...and so much more\n\nDraftFast provides support and consulting services that can help with all of these. [Let's get in touch today](mailto:ben.brostoff@gmail.com).\n\n# Contributing\n\nRun tests or set of tests:\n\n```sh\n# All tests\nnose2\n\n# Single file\nnose2 draftfast.test.test_soccer\n\n# Single test\nnosetests draftfast.test.test_soccer.test_soccer_dk_no_opp_d\n```\n\nRun linting\n\n```\nflake8 draftfast\n```\n\n# Credits\n\nSpecial thanks to [swanson](https://github.com/swanson/), who authored [this repo](https://github.com/swanson/degenerate), which was the inspiration for this one.\n\nCurrent project maintainers:\n\n- [BenBrostoff](https://github.com/BenBrostoff)\n- [sharkiteuthis](https://github.com/sharkiteuthis)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbrostoff%2Fdraftfast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenbrostoff%2Fdraftfast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbrostoff%2Fdraftfast/lists"}