DraftKings Python Client

repository·v3·Indexed 41 days ago

https://github.com/jaebradley/draftkings_client

A Python library (version 3.1.0) for interacting with DraftKings' unauthenticated HTTP endpoints to retrieve sports data, contests, and player information. It provides a Client class to fetch resources such as draft group details, available players, and game type rules, returning data as immutable Python dataclasses.

Tokens
3.4K
Snippets
21
Records
25
Agent score
100%

What's inside DraftKings Python Client

  1. Overview of the DraftKings Python Client

    v3

    The draft_kings client is a Python library designed to interact with DraftKings' unauthenticated HTTP endpoints. It allows users to fetch data for various resources, such as contests for specific sports or draftable players for a given contest, along with relevant metadata.

    Note: DraftKings does not provide an official, well-documented public API. This client interacts with endpoints that are currently accessible without authentication, but because these endpoints are not officially supported by DraftKings, the client makes no guarantees regarding consistent availability or behavior.

  2. Understand the output data format

    v3

    Data returned by the API is provided as immutable custom objects using Python dataclasses.

    Key characteristics:

    • Immutability: Objects use the frozen property, meaning they cannot be modified after creation.
    • Type Hinting: Objects are designed to work with Python 3 type-hinting to help discern expected field types.
    • Optional Fields: Most fields are Optional (can be None). This design choice prevents deserialization errors if DraftKings removes a field from their response; instead of crashing, the field will simply return None.

    Output objects are located in the draft_kings.output.objects module, organized into sub-modules corresponding to each endpoint.

  3. Recommended data retrieval workflow

    v3

    Since there are no subscription or real-time update endpoints, follow this polling pattern to gather data:

    1. Fetch Contests: Use client.contests(sport=...) to get the set of contests for the required Sports.
    2. Identify Draft Groups: Extract the Draft Group IDs associated with those contests.
    3. Fetch Group Data: Use the specific group-related APIs (like available_players, draft_group_details, or draftables) using those IDs to get the granular information you need.
    4. Repeat: Periodically repeat these operations to refresh your data, as there is no mechanism to subscribe to updates.
  4. Set up the local development environment

    v3

    To set up the development environment, use the provided build.sh Bash script. This script verifies that Python 3 is installed and installs the required version of Poetry.

    After running the script, pay attention to the standard output; it will provide specific instructions on how to add the Poetry bin directory to your PATH environment variable. Project dependencies and metadata are managed via pyproject.toml.

    ./build.sh
  5. Install the DraftKings Python Client via pip

    v3

    The draft-kings library can be installed from PyPI using pip. This client provides access to various undocumented, unauthenticated HTTP endpoints exposed by draftkings.com.

    Requirements:

    • Python version: 3.7+
    • Version Note: Use version 3.x for active development. Version 2.x is currently being deprecated.
    pip install draft-kings
  6. Run tests locally

    v3

    Tests are organized into two main categories:

    • Unit tests: Located in the tests/unit directory.
    • Integration tests: Located in the tests/integration directory.

    Note that for extensive integration tests (such as those for specific API methods), tests are often grouped into separate files within the tests/integration/client directory to maintain clarity, even if the implementation resides in a single file like client.py.