Making An API using Python and Flask

I created a Horoscope API, using pyhoroscope package.

I used Flask and hosted it on Heroku. Heroku is free and price you, as you grow. It provides, for free 1 dyno. A dyno is an instance of your application running and responding to requests.

Installing Heroku tool belt
sudo apt-add-repository 'deb ./'
curl | sudo apt-key add -
sudo apt-get update
sudo apt-get install heroku-toolbelt
sudo apt-get install ruby libopenssl-ruby ruby1.8-dev
sudo apt-get install libreadline-ruby

This is how my python code looks like, which fetches and returns data from pyhoroscope package. For Python App Heroku needs a requirements.txt, so add it too. Add a Procfile too. Read more here.

You need to follow the following steps to create a git repository on Heroku as remote.

  1. Create an app on heroku.
  2. git clone it.
  3. git add all your files.
  4. git commit.
  5. git push your files.

If you receive error,

Try on the url after the completion
if still not works check the error code, I got <strong>code=H14</strong> desc="No web processes running" method=GET path="/",
using heroku logs

check the error code, here it’s H14, find how to solve it using this. For this particular error, you need to scale your dynos from 0 to 1.

#use this
heroku ps:scale web=1

Read more about deploying your app from here.

#git, #heroku, #herokuapp, #horoscope-api, #programming, #python