
Python Flask Apps using Swagger API deployed on Heroku Cloud Platform
Deploying a Python Flask app on Heroku
Three Flask Projects used in this blog
- IMDb Movie Ratings
- Machine Learning API for Iris species prediction
- Google Text to Speech(gtts) conversion Flask App

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
ML API : https://github.com/karthikeyan9475/ml-random-forest-flask-api/tree/master/ml-random-forest-flask-api
Text to Speech : 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.
In both cases, clone the GitHub projects and try execute it in local flask development server.
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.

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.

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.

Heroku Deployment steps
- Signup for Heroku account
- Keep
Procfilefile in your project folder, where you need to mention the web server and flask app instance pyfile
web: gunicorn wsgi:app3. Generate the python dependencies in requirements.txt file, also add the respective web server, (eg — gunicorn)
pip freeze > requirements.txt3. Git initialize and commit the file
git initgit add -Agit commit -m "first commit!"
4. Create Heroku app (if name not given, random names will be assigned)
heroku create imdb-internet-movie-database5. Push it to heroku
git push heroku master6. To open the Heroku app : heroku open
7. To get usage stats : heroku ps -a imdb-internet-movie-database
8. To get recent logs in CLI : heroku logs — tail
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.
Thanks for reading. Happy Flasking !!
