quandl / quandl-python

MIT License
1.37k stars 336 forks source link

getting all codes from a database #92

Closed chivalry123 closed 6 years ago

chivalry123 commented 6 years ago

I try to get all the codes from FRED using:

quandl.get("FRED/codes")

It does not work... however, did I miss anything? Thank you.

mbasset commented 6 years ago

Hi @chivalry123,

The method you are using is not meant for that type of call. To retrieve a zip file containing a list of codes for time-series datasets in FRED programmatically you could use something like:

import requests

url = "https://www.quandl.com/api/v3/databases/FRED/codes"
api_key = "<your api key here>"

resp = requests.get(url, data={"api_key": api_key}, stream=True)

with open("FRED_codes.zip", "wb") as f:
    for chunk in resp.iter_content(chunk_size=1024):
        f.write(chunk)
        f.flush()

And then use a library like zipfile to extract the csv in the zip.