Simply downloaded the CFBD Starter Pack? Here is how one can transcend the CSVs utilizing the official Python shopper to drag dwell and up to date information from the CollegeFootballData API.
First off, thanks for selecting up the CFBD Starter Pack! It offers you cleaned, historic information throughout a number of seasons and is ideal for constructing fashions, dashboards, and analytics workflows.
👉 Don’t have the Starter Pack but? Seize it now and observe alongside.
However what if you wish to pull in more moderen or dwell information? That’s the place the CollegeFootballData API and official Python shopper are available.
Let’s stroll by how one can set it up and fetch new information.
🔧 Step 1: Set up the Python Shopper
Set up the bundle:
pip set up cfbd
🔐 Step 2: Set Your API Key
You’ll want an API key (free or Patreon tier) from the CFBD web site. Upon getting it, set it as an setting variable:
export BEARER_TOKEN=”your_api_key_here”
Then arrange the configuration in your Python code:
import cfbd
import os
configuration = cfbd.Configuration(
access_token=os.environ[“BEARER_TOKEN”]
)
🚀 Step 3: Fetch Knowledge Utilizing an API Shopper
The Python shopper makes use of context managers to deal with the API session. Here is how one can fetch adjusted participant passing stats:
with cfbd.ApiClient(configuration) as api_client:
api_instance = cfbd.StatsApi(api_client)
# Instance: get superior recreation stats for Michigan in 2023
response = api_instance.get_advanced_game_stats(
yr=2023,
crew=”Michigan”
)
print(response)
This similar sample works for all endpoints.
📘 Examples You Can Attempt
Listed below are a couple of sensible snippets to get began:
Current Video games
with cfbd.ApiClient(configuration) as api_client:
games_api = cfbd.GamesApi(api_client)
video games = games_api.get_games(yr=2024, week=13)
for g in video games:
print(f”{g.away_team} at {g.home_team}: {g.away_points}-{g.home_points}”)
Group Field Scores
with cfbd.ApiClient(configuration) as api_client:
stats_api = cfbd.GamesApi(api_client)
field = stats_api.get_game_team_stats(yr=2024, week=13)
for recreation in field:
print(recreation)
Historic Betting Traces
with cfbd.ApiClient(configuration) as api_client:
betting_api = cfbd.BettingApi(api_client)
video games = betting_api.get_lines(yr=2024, week=13)
for recreation in video games:
for line in recreation.strains:
print(f”{recreation.away_team} @ {recreation.home_team}: {line.formatted_spread} ({line.supplier})”)
🧠 Mix with the Starter Pack
The Starter Pack has historic EPA, recruiting, and drive/play-level information. You’ll be able to lengthen it by:
Merging latest API information along with your historic CSVsRunning your fashions on up-to-date weekly metricsBuilding dashboards a number of sorts of information
🛑 Watch Your Limits
In case you’re utilizing the Free Tier, you’ll be capped at 1,000 calls/month. Think about bumping to a Patreon plan for extra entry (and goodies like climate, superior metrics, and the GraphQL API).
You’ll be able to verify your remaining calls at any time both by way of the X-CallLimit-Remaining HTTP header returned with all responses or by way of the information endpoint (doesn’t depend in opposition to limits):
with cfbd.ApiClient(configuration) as api_client:
api_instance = cfbd.InfoApi(api_client)
api_response = api_instance.get_user_info()
print(api_response)
💬 Questions or Suggestions?
Be part of the group on Discord or try the interactive API docs to discover each endpoint.