Python interface for the football-data.org api from Daniel.
Project description
Football Data Api (Python Interface)
1. Introduction
This tool was built using the api provided by football-data.org so all kudos go to Daniel, the creator of that tool.
The intend of the tool is to simplify requests to the api for python use. It does not rearrange any of the responses, it simply offers an interface and returns the response in a dictionary format.
2. How to install it.
3. How to use it.
3.1 Starting
After installing the package, simply create a CompetitionData object. The CompetitionData object accepts two optional arguments: competition name and plan. Plan refers to the tier system that football-data.org uses to manage the payment system. You can find out more about plans here. The default plan is Tier One which is the free tier. The default competition is an empty string. If you provide a competition name, make sure it has the same name as on football-data.org.
Instantiate CompetitionData object:
>>> from football_data_api import data_fetchers
>>> data = data_fetchers.CompetitionData()
3.2 Setting the competition
If you are not sure which competitions you can choose from or how the competition is named exactly, you can call the get_available_competitions method that will return a dictionary with all available competitions as keys and their id as values. The available competitions to you will be based on the currently set plan.
>>> data.get_available_competitions()
{'série a': 2013,
'championship': 2016,
'premier league': 2021,
'european championship': 2018,
'uefa champions league': 2001,
'ligue 1': 2015,
'bundesliga': 2002,
'serie a': 2019,
'eredivisie': 2003,
'primeira liga': 2017,
'primera division': 2014,
'fifa world cup': 2000}
If there is ambiguity or you are not sure what competition the competition name relates to, you can find more details here To set a competition you simply assign the competition name to the competition attribute of the CompetitionData object.
>>> data.competition = 'premier league'
>>>
A KeyError will be raised if the competition name isn't available. The competition that is being set is the current competition, changing this is not supported at the moment.
Once you have set a competition, you can start querying information about that competition. Currently on a competition level, the information you can ask for relates to the competition itself, the teams in the competition and the matches (games) in the competition.
To get information, the method get_info(type, filters as kwargs) should be called. The first (excluding self) argument type refers to the type of information you are looking for. As said, three types are currently supported for competitions, 'teams', 'matches', 'competition'. Other arguments passed, should be passed as keyword arguments and will be used to filter the response. Common filters are: dateFrom=yyyy-mm-dd, dateTo=yyyy-mm-dd, id=int, matchday=int, status=string.
>>> teams_in_premier = data.get_info('teams')
>>> from datetime import datetime
>>> date_today = datetime.today()
>>> matches = data.get_info('matches', dateFrom='2018-08-01', dateTo=date_today)
The date filters can be passed in the format above or as python's datetime objects. id refers to the specific team id, matchday refers to the matchday in the current season (e.g. matchday 1 of season 2018-2019), status is an important filter for matches as it refers to the progress of games, you can use status to only get games that are in progress by passing status='IN_PLAY', a full description of match status can be found here. When a filter is passed that is not supported by football-data.org a ValueError will be raised. A complete list of filters and how to use them can be found here.
>>> games_in_play = data.get_info('matches', status='IN_PLAY')
Note on filters: Not all filters work on all type of request (e.g. passing a matchday filter when looking up teams doesn't make sense). Currently these checks are not included in the interface, when an invalid filter is passed, the api will simply return an unfiltered result.
4. Next Steps
Next items to be included:
- Fetchers for info about teams and their players.
- Keep track of api request for heavy api use (Limit of 10 per minute at the moment which is not being checked by this interface).
- Include possibility to set competition by id.
N.B.
Please feel free to contribute to this project, I made this with my own needs in mind and therefore didn't include all useful functionality.
Project details
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
File details
Details for the file football_data_api-0.0.6.tar.gz
.
File metadata
- Download URL: football_data_api-0.0.6.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59ac14266a615801a3aec48bc9481d5f3b3bcbe61b54733ab76d782ad949e18d |
|
MD5 | 9a09a398180ddc2172dcf5dd2ad5155b |
|
BLAKE2b-256 | 21bde455cc48084265095be312d0787a8e85bc35398ed62eb937f02ec860720d |
File details
Details for the file football_data_api-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: football_data_api-0.0.6-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 827bbf9e453eb1d472927b9b5a359506ea876fc8e3cd3f7cfff7af3a1efe3d4f |
|
MD5 | 1e26975cd63f735996c271b511f761bd |
|
BLAKE2b-256 | 4eb4999b548aab7046bf28262f0a8a0ffc08843efd0a8820f14c74e8d866cd2c |