Example how to use Flask to build an API for Machine Learning data requests
API<->Wrapper<->Model<-training Model
- ml_api.py: The API implemented as WSGI
The pathlib library is included in all versions of python >= 3.4. Therefore I recommend using the most up2date version of Python 3. In addition we want to use the packages Flask for our API and Scikit Learn for loading our trained model.
$ sudo pip install -U sklearn, flask
$ sudo apt-get install git
$ git clone https://github.com/.../....git api_directory
- Debug mode should never be used in a production environment!
- Flask Dev Server should never be used in a production environment!
Run Dev Server with:
$ FLASK_APP=ml_api.py flask run
* Running on http://localhost:5000/
Now, one can use tools like wget, cURL, Python (Requests) or your web browser to communicate with the API. If they aren't already installed, use:
$ sudo apt-get install curl