Last article, I introduced pulling your league’s data from Yahoo’s API in a Python script. Today, I’m going to show you a better way to do that very same thing.

In my last article dkempiners’ python-yahooapi code was used to do the heavy lifting, but admittedly I didn’t have a great understanding of how it worked and it was clunky in ways. This week we’re going to use josuebrunel’s myql code base, which at least for me was cleaner to use and easier to understand.

Since it seemed like more than a few people tried to follow along and do it themselves last week, this article will simply show how to use it, but won’t go anywhere near a step-by-step level of detail. Some coding knowledge is expected, in other words. If you have questions, I’ll do my best to answer them.


The Quick n’ Dirty Tutorial

So, download the code, install the necessary packages yada, yada. The Readme file for the repository is pretty helpful for getting set up.

The biggest thing you have to do to get the code working is save a .json file with your consumer secret and consumer key stored in it. I had never used a Json file before but after a little old fashioned trial-and-error, I figured out the format of such a file looks something like this:

Screen Shot 2015-05-05 at 9.04.27 PM


Save that as credentials.json in wherever your working directory is. After that, there isn’t much else you have to do to the code to get it to work. If the amount of files overwhelms you a little, all the action occurs in ‘’ and ‘’.

Skipping straight to the end, running the following lines of code pulls the same Friends and Family league data we did last week:

Screen Shot 2015-05-05 at 9.58.24 PM

Overall I think this is a much cleaner way of accessing the API in the way the response variable is  built in the format of a SQL query on the fantasysports.leagues table with the league key I specified. This package even has some cool features like opening your browser automatically to get the verifier and storing your access token in the same credentials.json file after you get the code to work once.

These words should make sense to anyone who tries to do this, I promise.


Looking Ahead

I still have no idea how to parse the json (or XML) output from the API, so that’s the next morsel on my plate of knowledge. I also have to start building/designing what I’ll call the warehouse architecture to store all this league data.

CSV files? Txt files? Open the data in R or Excel? No, definitely not Excel. Make a whole SQL or other type of database? What is Hadoop anyway?

That’s what my mind looks like right now.

I’ll experiment with different things, but if anyone has experience in these sorts of matters, please feel free to chime in. I’m not afraid to throw my hat into the “big data” ring, which is a nice term for impressing your single 35 year old boss, but I’m also not convinced it is necessary.



  1. The Jerk Store says:

    Theses articles are money! Do you have anything for CBS leagues?

    • paul

      paul says:

      @The Jerk Store: Thanks Jerk Store. This is just the boring pre-work part too. Nothing for CBS, if I made a version that didn’t use Yahoo’s API, I’d probably do ESPN first.

  2. Pouss-Pouss says:

    I just may have to indulge in this. Wow. Thank you.

    Separate but related question: Do you know how Yahoo calculates their in-season player “Rank” that’s listed beside their “O-Rank?” I’d like to know the formula they use and whether it’s adjusted for nonstandard league formats (I don’t think it is). Any idea?

    • paul

      paul says:

      @Pouss-Pouss: I don’t know the specifics of how it is calculated, I don’t think it’s customized specific league types.

      Would be a cool stat project to reverse-engineer them…

      • goodfold2 says:

        @paul: wow, i always thought it was centered to league specs, jesus, that’s fairly worthless if it isn’t, eh? Damn. Now that i went and compared leagues yeah, any player is the same value in every league.

  3. FredWord

    Zunino's kitten Felix says:

    My brain can’t process that.

    • goodfold2 says:

      @Zunino’s kitten Felix: this is a very popular answer around here, over 1 per week usually.

Comments are closed.