Python Flask Apps using Swagger API deployed on Heroku Cloud Platform

Deploying a Python Flask app on Heroku

Karthikeyan Sivabaskaran
Nov 8 · 3 min read

Three Flask Projects used in this blog

  1. IMDb Movie Ratings
  2. Machine Learning API for Iris species prediction
  3. Google Text to Speech(gtts) conversion Flask App
Flask app use cases used in this blog

Flask

Flask is a popular Python web framework used for developing web applications.

Swagger

Creates Swagger 2.0 API documentation for all your Flask views extracting specs from doc strings or referenced YAML files. The Swagger UI is embedded and docs by default available in **/apidocs/index.html**

Heroku

Heroku is a cloud platform that lets companies build, deliver, monitor and scale apps. Projects in this blog is deployed on Heroku free tier platform. Monthly 550 hours free usage for unverified credit card account and 1000 hours free usage for verified credit card account.


GitHub Code base

IMDb : https://github.com/karthikeyan9475/gtts-text-to-speech/tree/master/gtts-text-to-speech

Heroku Deployed URL links for 3 flask apps

IMDb : https://imdb-internet-movie-database.herokuapp.com/apidocs/
ML API : https://ml-random-forest-flask-api.herokuapp.com/apidocs/
Text to Speech : https://gtts-text-to-speech.herokuapp.com/apidocs/

Note

  • Some times access to these links gives site blocked due to the browser settings in your machine.
  • And, these apps are deployed in Heroku Free usage. So, there may be a chance that apps may stop working in a month when it exceeds the monthly usage limit.

IMDb Movie Ratings

IMDbPY is a Python package useful to retrieve and manage the data of the IMDb movie database about movies, people, characters and companies.

https://imdb-internet-movie-database.herokuapp.com/apidocs/

Machine Learning API for Iris Species prediction

Flask API to predict the Iris flower category. API is exposed in a way to predict for single input or multiple rows in a single input csv file.

https://ml-random-forest-flask-api.herokuapp.com/apidocs/

Google Text to Speech(gtts) conversion

Type the input string in Swagger input text box. Flask app will convert it to audio file and send it back as an attachment in browser. This may not work in some browsers due to some security reasons, because this will save the input text which is sent by the user. So, in that case you can download the GitHub code and run it in your local flask development server and test it.

https://gtts-text-to-speech.herokuapp.com/apidocs/

Heroku Deployment steps

  1. Signup for Heroku account
  2. Keep Procfile file in your project folder, where you need to mention the web server and flask app instance pyfile
web: gunicorn wsgi:app
pip freeze > requirements.txt
git initgit add -Agit commit -m "first commit!"
heroku create imdb-internet-movie-database
git push heroku master

Wrapping up

I hope this will help you to get a guideline to use Swagger in Flask apps and deploy the same on Heroku cloud platform.

Karthikeyan Sivabaskaran

Written by

Data Engineer at Tiger Analytics

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade