Skip to main content

AFL API Python Package

Overview​

The Champion Data AFL API Python Package allows users to connect to the Champion Data API and access the data contained in its endpoints. Each endpoint method will retrieve a response from the server and transform it to a tabular data format. Authorized access to the API is required.

Installation​

Environment setup (Optional)​

The package requires Python 3.9 or later with pip. To avoid crashes between dependencies, it is recommended that the package is used within a virtual environment (venv).

Navigate to the directory where the package is supposed to be installed, open a terminal/CMD within that directory and execute the following commands:

Creating a virtual environment​

The following command will create a virtual environment named .venv:

python -m venv .venv

Using the virtual environment​

Activate the created virtual environment by executing one of the following commands for the respective operating system.

On Linux/MacOS​
source .venv/bin/activate
On Windows​
.venv\Scripts\activate.bat

Binaries​

Inside the same directory where the virtual environment was created, install the pacakge via pip wheels by executing:

pip install "http://www.championdata.com/scratch/api/champion_data-[version number]-py3-none-any.whl"

[version-number] in the above will correspond to the version of the Python package you are attempting to install. You can find the most up to date version number of the package on the Python Package Documentation DocHub.

Using the package​

Credentials​

Your authorised API credentials must be provided as text strings.

# python3
api_un: str = "your.username@address"
api_pw: str = "password"

Instantiate the API object​

An API object can then be created using the given credentials.

# python3
import champion_data

api: champion_data.API = champion_data.API(
username=api_un,
password=api_pw,
verbose=True,
)

Using endpoints​

Simply call endpoints using the instantiated API object.

# python3
api.season()
>> hitting url: https://api.afl.championdata.io/v1/leagues/1/levels/1
>> hitting url: https://api.afl.championdata.io/v1/leagues/1/levels/1/seasons/2024
>> season.id competition.id competition.code competition.name ... nextRound nextRoundStart lastRound lastRoundEnd
0 2024 2024012425 AFL2024 AFL Premiership Season 2024 ... 12 2024-05-30T09:30:00.000Z 11 2024-05-26T06:40:00.000Z