espn-api Python Library

repository·master·Indexed 21 days ago

https://github.com/cwendt94/espn-api

A Python interface for extracting data from ESPN's Fantasy API. It provides support for Football and Basketball leagues, with Hockey and Baseball support currently in development. The library allows users to initialize a League object using a league_id and year to interact with fantasy sports data.

Tokens
643
Snippets
4
Records
4
Agent score
25%

What's inside espn-api

  1. Install the espn-api package

    master

    You can install the package via pip or by cloning the repository. For Python versions >= 3.9, it is recommended to use the requirementsV2.txt file and pytest instead of setup.py and nosetests.

    # Using pip (Recommended)
    pip install espn_api
    
    # Using Git and Requirements.txt (Recommended for Python >= 3.9)
    git clone https://github.com/cwendt94/espn-api
    cd espn-api
    python -m venv myenv
    # On Windows:
    myenv\Scripts\activate.bat
    # On Unix/macOS:
    source myenv/bin/activate
    pip install -r requirementsV2.txt
  2. Initialize a League for a specific sport

    master

    To interact with an ESPN Fantasy league, import the League class from the specific sport module (football, basketball, hockey, or baseball) and initialize it with a league_id and year.

    Note: As of the current version, Hockey and Baseball support are in development.

    # Football API
    from espn_api.football import League
    
    # Basketball API
    from espn_api.basketball import League
    
    # Hockey API
    from espn_api.hockey import League
    
    # Baseball API
    from espn_api.baseball import League
    
    # Initialize the league
    league = League(league_id=222, year=2019)
  3. Run tests for espn-api

    master

    If you are developing or testing the package, use pytest for Python versions >= 3.9. For older versions, you can use nosetests via setup.py.

    # Recommended for Python >= 3.9
    pytest
    
    # Not recommended for Python >= 3.9
    python3 setup.py nosetests
  4. Debug ESPN API requests and responses

    master

    When reporting bugs, you can enable debug mode by passing debug=True to the League constructor. This will print all requests and responses from ESPN's API to the console. It is recommended to pipe this output to a text file due to the high volume of data.

    # Enable debug mode to see raw API traffic
    league = League(league_id=1245, year=2019, debug=True)