Git · Python

Making An API using Python and Flask

This post is having some tips and notes about how to create a simple  API.

It’s fun to code something useful right?

I created a Horoscope API, using pyhoroscope package, I created some days back.

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.


To install Heroku on your Ubuntu machine :

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.


After this you need to follow the following steps :

  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 an 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.


And you are done. 
Now go and try something new. 🙂


One thought on “Making An API using Python and Flask

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s