modified api script so that it can be used with uwsgi