A Python wrapper for the Sportradar APIs
Project description
Python wrapper for Sportradar APIs
This is a Python wrapper for the sports APIs provided by Sportradar. You'll need to sign up for an API key to use the service. Luckily, Sportradar provides a free tier that allows for 1,000 API queries per month and up to 1 query per second. The package currently only supports the Soccer INTL Trial v3 API, but I hope to expand it to support their APIs for other sports in the future.
Installation
The easiest way to start using this package is to install it via PyPI using pip
:
$pip install sportradar
If you'd prefer to clone the repository and install it yourself, follow these steps:
- Clone this repo:
$git clone https://github.com/johnwmillr/SportradarAPI.git
- Enter the cloned directory:
$cd SportradarAPI
- Install:
$python setup.py install
Usage
Below is a brief demonstration of using the package to download data for the 2018 FIFA World Cup.
import sportradar
# Create an instance of the Sportradar API class
sr = sportradar.API("paste your api key here")
# Get a list of all tournaments
tournaments = sr.get_tournaments().json()
# Get info on the 2018 World Cup (Teams, Rounds, etc.)
worldcup = sr.get_tournament_info(tournaments['tournaments'][4]['id']).json()
# Get more information on each team in the World Cup
teams = []
team_counter = 0
for group in worldcup['groups']:
for team in group['teams']:
team_counter += 1
team_id = team['id']
team_name = team['name']
print("({}): {}, {}".format(team_counter, team_name, team_id))
try:
teams.append(sportsradar.get_team_profile(team_id).json())
except Exception as e:
print("Error: {}".format(e))
time.sleep(5) # wait 5 seconds before next API call
# Save the team data to a .json file
print("Saving the data...", end="", flush=True)
with open("world_cup_team_data.json", "w") as outfile:
json.dump(teams, outfile)
print(" Done.")
Example projects
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
Hashes for sportradar-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a66edb7a010e91158813d1f795da5136aaaacd703492ae6eb2cdc57b5a374b2 |
|
MD5 | 209ba76a238b553fb9525a1eda581e35 |
|
BLAKE2b-256 | 445f231fb18e20bf5641d8bf98cc38addfe900b6a8eecc7908ca3b879c0c230b |