John Salvetti John Salvetti - 22 days ago 4
PHP Question

Get live NFL scores/stats to read and manipulate?

I need some sort of database or feed to access live scores(and possibly player stats) for the NFL. I want to be able to display the scores on my site for my pickem league and show the users if their pick is winning or not.

I'm not sure how to go about this. Can someone point me in the right direction?

Also, it needs to be free.


Disclaimer: I'm the author of the tools I'm about to promote.

Over the past year, I've written a couple Python libraries that will do what you want. The first is nflgame, which gathers game data (including play-by-play) from's GameCenter JSON feed. This includes active games where data is updated roughly every 15 seconds. nflgame has a wiki with some tips on getting started.

I released nflgame last year, and used it throughout last season. I think it is reasonably stable.

Over this past summer, I've worked on its more mature brother, nfldb. nfldb provides access to the same kind of data nflgame does, except it keeps everything stored in a relational database. nfldb also has a wiki, although it isn't entirely complete yet.

For example, this will output all current games and their scores:

import nfldb

db = nfldb.connect()

phase, year, week = nfldb.current(db)
q = nfldb.Query(db).game(season_year=year, season_type=phase, week=week)
for g in q.as_games():
    print '%s (%d) at %s (%d)' % (g.home_team, g.home_score,
                                  g.away_team, g.away_score)

Since no games are being played, that outputs all games for next week with 0 scores. This is the output with week=1: (of the 2013 season)

CLE (10) at MIA (23)
DET (34) at MIN (24)
NYJ (18) at TB (17)
BUF (21) at NE (23)
SD (28) at HOU (31)
STL (27) at ARI (24)
SF (34) at GB (28)
DAL (36) at NYG (31)
WAS (27) at PHI (33)
DEN (49) at BAL (27)
CHI (24) at CIN (21)
IND (21) at OAK (17)
JAC (2) at KC (28)
PIT (9) at TEN (16)
NO (23) at ATL (17)
CAR (7) at SEA (12)

Both are licensed under the WTFPL and are free to use for any purpose.

N.B. I realized you tagged this as PHP, but perhaps this will point you in the right direction. In particular, you could use nfldb to maintain a PostgreSQL database and query it with your PHP program.