This document explains all environment variables and configuration options used by FantasyManager.
FantasyManager is configured through environment variables, making it portable across local development, devcontainers, and cloud deployments.
Current Architecture:
- Python Engine (FastAPI) — core domain logic + HTTP API
- Go Client SDK — generated from OpenAPI spec
- PostgreSQL — database models defined (optional for demo mode)
- In-memory store — default for zero-setup demos
These variables are actively used by the codebase.
| Variable | Description | Required | Example |
|---|---|---|---|
ESPN_LEAGUE_ID |
Your ESPN fantasy league ID | Yes (for ESPN sync) | 12345678 |
ESPN_YEAR |
Season year | Yes (for ESPN sync) | 2024 |
ESPN_S2 |
ESPN authentication cookie | Private leagues only | AEC...long string |
ESPN_SWID |
ESPN user identifier (GUID with braces) | Private leagues only | {XXXXXXXX-XXXX-...} |
ESPN_MY_TEAM_ID |
Manual override for your team ID | Optional | espn-5 |
How to get ESPN cookies (for private leagues):
- Log into ESPN Fantasy in your browser
- Open Developer Tools → Application → Cookies
- Find
espn_s2andSWIDcookies - Copy values to your
.envfile
| Variable | Description | Default |
|---|---|---|
DB_URL |
PostgreSQL connection string | Uses in-memory mock data if not set |
Format: postgresql+psycopg://user:password@host:port/database
Devcontainer default: postgresql+psycopg://dev:dev@postgres:5432/fantasy
Note: The current API routes use in-memory mock data by default. Database models are defined in
apps/engine-py/db/models.pybut not yet wired to routes. ESPN sync populates the in-memory store.
These variables are documented for future development but have no effect currently.
| Variable | Intended Purpose | Status |
|---|---|---|
REDIS_URL |
Redis connection for caching | In devcontainer stack, not used in code |
ENGINE_PORT |
Override default port | Hardcoded to 8000 |
ENGINE_LOG_LEVEL |
Log verbosity (debug/info/warning/error) | Not implemented |
ENGINE_WORKERS |
Uvicorn worker count | Not implemented |
ENABLE_CACHE |
Toggle Redis caching | Not implemented |
CACHE_TTL_SECONDS |
Cache TTL for projections | Not implemented |
ENABLE_RATE_LIMITING |
Throttle external API calls | Not implemented |
RATE_LIMIT_CALLS_PER_MINUTE |
Rate limit threshold | Not implemented |
EXTERNAL_API_KEY_FFPROS |
FantasyPros API key | Not implemented |
EXTERNAL_API_KEY_NEWS_API |
News API key | Not implemented |
Create apps/engine-py/.env for local configuration:
# ESPN Integration (required for real league data)
ESPN_LEAGUE_ID=12345678
ESPN_YEAR=2024
ESPN_S2=your_espn_s2_cookie_here
ESPN_SWID={YOUR-SWID-GUID-HERE}
# Optional: Manual team ID override
# ESPN_MY_TEAM_ID=espn-5
# Optional: Database (omit to use in-memory mock data)
# DB_URL=postgresql+psycopg://dev:dev@postgres:5432/fantasyThis file is gitignored and loaded automatically by the devcontainer.
# Database (required for production)
DB_URL=postgresql+psycopg://user:password@prod-db:5432/fantasy
# ESPN (if using ESPN sync in production)
ESPN_LEAGUE_ID=12345678
ESPN_YEAR=2024
ESPN_S2=${ESPN_S2_SECRET}
ESPN_SWID=${ESPN_SWID_SECRET}The devcontainer automatically provides:
- Python 3.13 with Poetry
- Go 1.22
- PostgreSQL at
postgres:5432 - Redis at
redis:6379(available but unused)
Default environment variables are set in .devcontainer/devcontainer.json:
{
"remoteEnv": {
"ENGINE_BASE_URL": "http://app:8000",
"DB_URL": "postgresql://dev:dev@postgres:5432/fantasy"
}
}Using infra/compose.yaml:
# Start all services
docker compose -f infra/compose.yaml up -d
# View logs
docker compose -f infra/compose.yaml logs -fEnvironment variables can be overridden:
services:
engine:
environment:
DB_URL: postgresql+psycopg://dev:dev@db:5432/fantasy
ESPN_LEAGUE_ID: "12345678"
ESPN_YEAR: "2024"gcloud run deploy fantasy-engine \
--image gcr.io/project/fantasy-engine \
--set-env-vars DB_URL=$DATABASE_URL \
--set-env-vars ESPN_LEAGUE_ID=$ESPN_LEAGUE_ID \
--set-env-vars ESPN_YEAR=$ESPN_YEAR \
--set-secrets ESPN_S2=espn-s2:latest,ESPN_SWID=espn-swid:latest- Private league? You need both
ESPN_S2andESPN_SWIDcookies - Cookies expired? Re-copy from browser (they expire periodically)
- Wrong league ID? Check the URL when viewing your league on ESPN
The /v1/me/team endpoint tries to match your ESPN_SWID to team owners. If it fails:
- Use
/v1/sync/espn/checkto see all teams and their owner IDs - Set
ESPN_MY_TEAM_ID=espn-Xmanually in your.env
- Ensure Postgres is running:
docker ps | grep postgres - Check connection string format includes
+psycopgdriver - Verify port 5432 is accessible
- Ensure
.envis inapps/engine-py/(not project root) - Restart the devcontainer after changes
- Check for typos in variable names
On startup, the Engine logs which configuration is active. Check the console output:
INFO: ESPN_LEAGUE_ID: 12345678
INFO: ESPN_YEAR: 2024
INFO: ESPN cookies: configured
INFO: Database: using in-memory mock data
You can also verify ESPN configuration via API:
curl http://localhost:8000/v1/sync/espn/check| Version | Date | Description |
|---|---|---|
| 1.0 | 2024-11-23 | Initial configuration document |
| 1.1 | 2025-02-02 | Updated to reflect implemented vs planned features |