I have generated a common Sklearn model for text classification which I want to make accessible in the cloud (there is no provider preference) as an API.

So far the closest solution that I managed to find is in this tutorial but it seems quite complex (getting the venv.zip dependencies package at the beginning is unclear, for instance) and specific (in my case NLTK and an external Stanford segmenter is involved for preprocessing and I cannot figure out where to put all these modules and how to invoke them).

Is there a decent and robust way to solve this challenge?

  • $\begingroup$ If you're not using AWS or GCE, which have simpler solutions, here's a dockerized solution. $\endgroup$ – Emre Aug 18 '17 at 16:47
  • $\begingroup$ You might want to look at github.com/orgesleka/webscikit. It is still work in progress, but you could subclass WebModel, override predict() and transform() and use the metadata dictionary to hold nltk and stanford segmenter. $\endgroup$ – orgesleka Dec 1 '17 at 9:27

If you want to deploy a scikit-learn model to the cloud and be able to access it through an API, I am guessing that you will want to access the predict method.


To build an API with python, the easiest is to use Flask or Django. I prefer Flask for these types of tasks because it has a simpler interface. Django offers you more lower-level control however.

You will have to create some route that the client will call by sending you the input data, and once you receive it on the server side, you'll just have to pass it through your Sklearn model, and send back the output to the client.

Run sklearn in the cloud

The other thing you need to take care of, is run Python on whatever cloud solution you'll use. In order to deploy your Flask/Django app, I would probably use Docker as it's well supported on many platform. Here is an example on how to deploy a Docker container on Azure


You can also use clipper.ai to create a simple standard REST API for predictions. It works with any containerized model (not just scikit-learn) and is scalable, all you need is Docker.


Flask is a python based package that is used to develop restful api services (api services). when you run your application (directly from a command window), you will get a message telling you that you should not use this app as its in production environment. running the app from a cmd and using it is very risky and not reliable. so how to use an application (web service) that developed using flask?

The answer is: you can use the IIS to host a flask application, but how to do this?

1- Install IIS: You’ll need to make sure that IIS is installed and configured with the CGI role service (this enables FastCGI as well).

2- lunch the IIS, make sure to run it as an administrator. - click yes for starting the Microsoft Web Platform

  • if you do not get this message, you need to install the Platform Installer

  • Search for WFastCGI

  • Select the appropriate Python version (3.4 or 2.7.9). Click “Add”, then click “Install”.

  • if you have problem in finding the WFastCGI, you need to download it from this page wfastcgi, you can run the following command: pip install wfastcgi

3- copy the wfastcgi.py from C:\Python34 (may be named C:\Python34_x86 if you had an existing Python34 directory) to your Flask application root.

4- Double click “Handler Mappings” (in the IIS)

5- Click “Add Module Mapping”

6- Click “Request Restrictions”. Make sure “Invoke handler only if request is mapped to:” checkbox is unchecked.

7- Go to the root server settings and click “FastCGI Settings”.

8- Double click it, then click the “…” for the Environment Variables collection to launch the Environment Variables Collection Editor.

9- Set the PYTHONPATH variable: - Name: PYTHONPATH, Value: your site directory

10- set the WSGI_HANDLER (my Flask app is named app.py so the value is app.app - if yours is named site.py it would be site.app or similar)

11- that set.

the credit is for this page, you will find more details. Deploying Flask on IIS

  • $\begingroup$ In general, the world of hosting is just so much easier if you don't try and do it on Windows! $\endgroup$ – Philip Kendall Nov 24 '18 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.