Python SDK for interacting with the Football World (FOWO) API
Project description
FOWOPY - Football World Python SDK
A Python SDK for interacting with the Football World (FOWO) API. This library simplifies the process of accessing fantasy football data through the FOWO API.
Features
- Simple, intuitive interface for accessing FOWO API endpoints
- Type-validated responses using Pydantic models
- Support for both CSV and Parquet bulk data downloads
- Automatic retries with exponential backoff
- Comprehensive test suite
Installation
pip install fowopy
Quick Start
from fowopy import FOWOClient, FOWOConfig
# Create a configuration object
config = FOWOConfig(fowo_base_url="http://api.footballworld.com")
# Initialize the client
client = FOWOClient(config)
# Check API health
response = client.get_health_check()
print(response.json()) # {'message': 'API health check: Status successful'}
# Get a list of leagues
leagues = client.list_leagues()
for league in leagues:
print(f"League: {league.league_name}, ID: {league.league_id}")
Configuration Options
The FOWOConfig class accepts the following parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
fowo_base_url |
str | http://0.0.0.0:8000 | Base URL for the FOWO API |
fowo_backoff |
bool | True | Enable exponential backoff for API calls |
fowo_backoff_max_time |
int | 30 | Maximum time in seconds to retry API calls |
fowo_bulk_file_format |
str | "csv" | Format for bulk file downloads ("csv" or "parquet") |
You can also set the base URL using the FOWO_API_BASE_URL environment variable.
API Endpoints
Health Check
response = client.get_health_check()
Leagues
# List all leagues
leagues = client.list_leagues()
# List leagues with pagination
leagues = client.list_leagues(skip=10, limit=20)
# Filter leagues by name
leagues = client.list_leagues(league_name="Premier League")
# Get a specific league by ID
league = client.get_league_by_id(5002)
Teams
# List all teams
teams = client.list_teams()
# Filter teams by league
teams = client.list_teams(league_id=5002)
# Filter teams by name
teams = client.list_teams(team_name="Manchester United")
Players
# List all players
players = client.list_players()
# Filter players by name
players = client.list_players(first_name="Bryce", last_name="Young")
# Get a specific player by ID
player = client.get_player_by_id(2009)
Performances
# List all performances
performances = client.list_performances()
# Filter performances by date
performances = client.list_performances(minimum_last_changed_date="2024-04-01")
Bulk Data Downloads
# Download player data as CSV (default)
player_data = client.get_bulk_player_file()
# Download player data as Parquet
config = FOWOConfig(fowo_bulk_file_format="parquet")
client = FOWOClient(config)
player_data_parquet = client.get_bulk_player_file()
# Other bulk data endpoints
league_data = client.get_bulk_league_file()
performance_data = client.get_bulk_performance_file()
team_data = client.get_bulk_team_file()
team_player_data = client.get_bulk_team_player_file()
Working with Bulk Data
CSV Example
import csv
from io import StringIO
# Get player data as CSV
player_file = client.get_bulk_player_file()
# Decode the byte content to a string
player_file_str = player_file.decode("utf-8-sig")
player_file_s = StringIO(player_file_str)
# Parse CSV
csv_reader = csv.reader(player_file_s)
rows = list(csv_reader)
# First row is the header
header = rows[0]
data = rows[1:]
Parquet Example
from io import BytesIO
import pyarrow.parquet as pq
import pandas as pd
# Configure client for Parquet
config = FOWOConfig(fowo_bulk_file_format="parquet")
client = FOWOClient(config)
# Get player data as Parquet
player_file_parquet = client.get_bulk_player_file()
# Load into pandas DataFrame
player_table = pq.read_table(BytesIO(player_file_parquet))
player_df = player_table.to_pandas()
Error Handling
The SDK uses the httpx library for making HTTP requests. Errors are handled as follows:
- HTTP status errors (4xx, 5xx) raise
httpx.HTTPStatusError - Network/connection errors raise
httpx.RequestError
When fowo_backoff is enabled (default), the SDK will automatically retry failed requests with exponential backoff.
try:
response = client.get_health_check()
except httpx.HTTPStatusError as e:
print(f"HTTP error: {e.response.status_code} - {e.response.text}")
except httpx.RequestError as e:
print(f"Request error: {str(e)}")
Development
Prerequisites
- Python 3.10+
- pip
Setup
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]"
Running Tests
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fowopy-0.0.2.tar.gz.
File metadata
- Download URL: fowopy-0.0.2.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a72be0f35f6178dfdd255bcfb8c5e4154f70f61a4a84eb280a87a87475419e2a
|
|
| MD5 |
ad90ef9fa88877dddc7cb877b83f22c6
|
|
| BLAKE2b-256 |
7b128f27bf049aaf5f4ec59f1cd6a147cd725a2f40c4bc84de46d31ea49ca66a
|
File details
Details for the file fowopy-0.0.2-py3-none-any.whl.
File metadata
- Download URL: fowopy-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1955708dca713a6fc344a7b6b62b16b895b8969a84bca354da306c8a55eb44be
|
|
| MD5 |
7b5f47b687d8cb639905428d5158852d
|
|
| BLAKE2b-256 |
d34fc08368d80c33011175b57a7818760dd893654beeef39e6bd00c62e51764e
|