Python client for the football-data.org API v4
Project description
football-api
A minimal Python client for the football-data.org API v4.
Provides both sync and async interfaces with full type safety via Pydantic models.
Installation
pip install football-api
Quick Start
Sync
from football_api import FootballClient
with FootballClient(api_key="YOUR_TOKEN") as client:
# Premier League standings
standings = client.get_standings("PL")
for entry in standings.standings[0].table:
print(f"{entry.position}. {entry.team.name} — {entry.points} pts")
# Today's matches
matches = client.get_matches()
for m in matches.matches:
print(f"{m.home_team.name} vs {m.away_team.name} [{m.status}]")
Async
import asyncio
from football_api import AsyncFootballClient
async def main():
async with AsyncFootballClient(api_key="YOUR_TOKEN") as client:
comp = await client.get_competition("PL")
print(comp.name, comp.current_season.current_matchday)
asyncio.run(main())
Environment Variable
Instead of passing api_key directly, set FOOTBALL_DATA_API_KEY:
export FOOTBALL_DATA_API_KEY="your-token-here"
client = FootballClient() # reads from env
API Methods
| Method | Description |
|---|---|
get_areas() |
List all areas |
get_area(id) |
Get area by ID |
get_competitions(areas=...) |
List competitions |
get_competition(id) |
Get competition by ID or code |
get_standings(comp_id, season=..., matchday=...) |
League table |
get_scorers(comp_id, season=..., limit=...) |
Top scorers |
get_matches(date_from=..., date_to=..., status=...) |
List matches |
get_match(id) |
Get single match |
get_head2head(match_id, limit=...) |
Head-to-head history |
get_competition_matches(comp_id, matchday=..., stage=...) |
Competition matches |
get_team(id) |
Get team details |
get_competition_teams(comp_id, season=...) |
Teams in competition |
get_team_matches(team_id, venue=..., status=...) |
Team matches |
get_person(id) |
Get person (player/coach/referee) |
get_person_matches(person_id, competitions=..., limit=...) |
Person matches |
All methods are available on both FootballClient (sync) and AsyncFootballClient (async).
Error Handling
from football_api import FootballClient, NotFoundError, RateLimitError
with FootballClient(api_key="YOUR_TOKEN") as client:
try:
team = client.get_team(99999)
except NotFoundError:
print("Team not found")
except RateLimitError:
print("Rate limit exceeded, slow down")
Exception hierarchy:
FootballAPIError— base for all API errorsAuthenticationError— invalid or missing token (HTTP 403)NotFoundError— resource not found (HTTP 404)RateLimitError— rate limit exceeded (HTTP 429)ServerError— server-side errors (HTTP 5xx)
Supported Competitions
The free tier includes several major leagues and competitions. See football-data.org for the full list.
Development
git clone https://github.com/ice1x/football-api.git
cd football-api
pip install -e ".[dev]"
pytest
License
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 football_api-0.1.0.tar.gz.
File metadata
- Download URL: football_api-0.1.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6d2d765b28a164a0d0255d1385513578eed1e7977fce58bbc52266ad541a521
|
|
| MD5 |
3318d3c126d653b04cdea4fd734180e4
|
|
| BLAKE2b-256 |
e4c5dd78a86e894c3cbe2d9d5c95e8d6d1b076b24c0d5cd906e692d082bf1a89
|
File details
Details for the file football_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: football_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b605df1de1fe8354de495f406d9c112f29dd69ca5c39064ff072821d09168479
|
|
| MD5 |
9fbd187e84906e2899e16557ff3b5d67
|
|
| BLAKE2b-256 |
994594a24791f1329942094ffd4959d40e2e5bc022eca47a9aafd0b2f0924b7d
|