Overview
This guide walks you through setting up Fantasy Basketball Analytics for local development or self-hosting. The application is built with Python Flask and requires OAuth credentials from Yahoo Developer Network.Prerequisites
Before you begin, ensure you have:Python 3.8+
Python runtime environment installed on your system
ngrok
For local development OAuth callback handling
Yahoo Developer Account
To create an application and obtain OAuth credentials
Git
To clone the repository
Installation Steps
Clone the Repository
First, clone the Fantasy Basketball Analytics repository to your local machine:
Install Python Dependencies
Install all required Python packages using pip:
View requirements.txt contents
View requirements.txt contents
The application requires the following packages:
requirements.txt
Consider using a virtual environment to isolate dependencies:
Create Yahoo Developer Application
Register your application with Yahoo to obtain OAuth credentials:
- Go to Yahoo Developer Network
- Click “My Apps” and create a new application
- Fill in the application details:
- Application Name: Fantasy Basketball Analytics (or your preferred name)
- Application Type: Web Application
- Callback Domain: You’ll update this after setting up ngrok
- Under API Permissions:
- Select Fantasy Sports
- Choose Read permissions
- Save your application and note the Client ID and Client Secret
Configure ngrok for Local Development
ngrok creates a secure tunnel to your localhost, which is required for Yahoo OAuth callbacks during development.
- Install ngrok from ngrok.com
- Start ngrok in a separate terminal window:
- Copy the HTTPS forwarding URL (e.g.,
https://abc123.ngrok.io) - Go back to your Yahoo Developer application settings
- Set the Redirect URI to:
https://your-ngrok-url.ngrok.io/callback
Set Up Environment Variables
Create a Then edit the
.env file in the project root with your configuration:.env file with your values:Environment Variables Explained
| Variable | Description | Required |
|---|---|---|
YAHOO_CLIENT_ID | Your Yahoo app’s Client ID from the developer console | Yes |
YAHOO_CLIENT_SECRET | Your Yahoo app’s Client Secret from the developer console | Yes |
FLASK_SECRET_KEY | Secret key for Flask session encryption (generate a random string) | Yes |
FLASK_ENV | Set to development for local development, production for deployment | No |
Generate a secure Flask secret key using Python:
Run the Application
Start the Flask development server:The application will start on
http://localhost:5000 with debug mode enabled.You should see output similar to:OAuth Setup Deep Dive
The application uses Yahoo’s OAuth 2.0 flow for authentication. Here’s how it works:OAuth Flow
- Login Request (
/login): User clicks login, app redirects to Yahoo with client ID - User Authorization: User approves app access on Yahoo’s site
- Callback (
/callback): Yahoo redirects back with authorization code - Token Exchange: App exchanges code for access token and refresh token
- API Requests: App uses access token to call Yahoo Fantasy API
- Token Refresh: When token expires, app uses refresh token to get new access token
Key Configuration Points
Inmain.py:126-138, the OAuth client is configured:
main.py
fspt-r provides read-only access to Fantasy Sports data.
Production Deployment
For deploying to production (e.g., Heroku):Configure Production Environment
Set environment variables in your hosting platform:
YAHOO_CLIENT_IDYAHOO_CLIENT_SECRETFLASK_SECRET_KEYFLASK_ENV=production(optional)
Update Yahoo App Redirect URI
Change the redirect URI in your Yahoo Developer app to your production domain:
API Endpoints Reference
The application exposes several internal API endpoints:Yahoo Data Endpoints
| Endpoint | Description | Parameters |
|---|---|---|
/api/scoreboard | Weekly matchup data | week (int) |
/api/season_avg | Season-long team statistics | None |
/api/league_settings | League configuration and categories | None |
/api/player_stats_week/<week> | Player stats for specific week | week (int) |
/api/player_stats_season | Season-long player stats | None |
/api/team_logo | Current user’s team logo URL | None |
/api/draft/keepers | Keeper players and draft data | None |
/api/bulk_matchups | Matchup data for multiple weeks | weeks (range) |
NBA Data Endpoints
| Endpoint | Description |
|---|---|
/api/nba_players | Active NBA players list |
/api/nba_player_stats/<player_id> | Individual player statistics |
Troubleshooting
Common Issues
OAuth callback fails
OAuth callback fails
- Verify your ngrok URL matches the redirect URI in Yahoo app settings
- Ensure you’re accessing via HTTPS (ngrok URL, not localhost)
- Check that your Client ID and Client Secret are correct in
.env - Make sure ngrok is still running (restart if needed)
No leagues showing up
No leagues showing up
- Confirm you have an active Yahoo Fantasy Basketball league
- Verify the league is H2H Categories (not Roto or Points)
- Check that you’re the owner or a member of the league
- Review browser console for API errors
NBA player data not loading
NBA player data not loading
- The NBA API may be temporarily unavailable
- Check your internet connection
- Review the console logs for specific error messages
- The app has a fallback to static player data if the live API fails
Token expired errors
Token expired errors
- The app automatically refreshes tokens, but if you see repeated errors:
- Clear your browser cookies and session data
- Log out and log back in
- Verify your Yahoo app credentials are still valid
Debug Endpoints
Two debug endpoints are available when logged in:/debug/league_settings- Raw league settings data from Yahoo/debug/scoreboard?week=1- Raw scoreboard data for a specific week
Next Steps
Quick Start Guide
Learn how to use the platform features
Contributing
Contribute to the project on GitHub