Dec. 09, 2014 04:12                                   flask-api                  

Flask API

        

I worked on a simple API using Flask, numpy, and pandas.

The API makes simple GET requests based on a unixtime start and stop range, pointed at an HDF5 binary data store.

The primary function looks like:

def get_temps(begin_utc, end_utc, format):
    store = pd.HDFStore('data.h5')
    df = store["df"]
    r = df[(df['timeStamp']>=begin_utc) & (df['timeStamp']<=end_utc)]
    store.close()
    if format == 'csv':
        return r.to_csv(index=False, header=False, columns= ["temp", "timeStamp"])
    else:
        return r.to_json(orient="records")

The code is here

Nice little foray into Flask.

             Previous Post                      Next Post