The open blogging platform. Say no to algorithms and paywalls.

10 Killer APIs for Your Next Python Project

A collection of useful public APIs you can use in your Python project

image

Designed by wayhomestudio on Freepik

We all have coded on some pretty awesome projects and you know we always need APIs for making our work more productive and automated. In this article, I present to you 10 killer public API’s that you can use in your next Python project. So put this article on your list and let's get started. Nothing is impossible, the word itself says I’m possible — Audrey Hepburn

👉NewsCatcher

Catch your everyday news headlines and article with this awesome API that allow you 10,000 calls per month. Handy API for your news Python project or you want to get daily news. API allows you to fetch news on different topics and even you can choose a country and language too. Check out the code below:

# Get your API : <https://newscatcherapi.com/>import requestsquery = "Tesla"
country = "US"
URL = f"<https://api.newscatcherapi.com/v2/search?q=\>"{query}\"&lang=en&countries={country}"payload={}
headers = {
  'X-API-KEY': 'Your API Key'
}r = requests.get(URL, headers=headers, data=payload)
news = r.text
print(news)

👉 Remove bg from image

If tired of doing the steps for removing the background from Photoshop then try this API that uses remove.bg API which accurately removes the background from any complex photo and images.

# Get Your API: <https://www.remove.bg/tools-api>
# pip install remove-bg-apifrom remove_bg_api import RemoveBg# Remove from File
bg = RemoveBg("Your API")
img = bg.remove_bg_file(input_path="img.jpg", out_path="out.jpg")# Remove from URL
img_url = "<https://www.example.com/img>"
img = bg.remove_background_from_img_url(input_url=img_url, out_path="out.jpg")

👉 Google Sheet API

Want to Fetch and Write on your Google Sheet programmatically? This handy API will solve your problem. This API uses Google Console API that connects you with your Google Sheet and you can read and write directly from Python.

# Get your API : <https://console.cloud.google.com/>
# pip install gspreadimport gspread as sheetgs = sheet.service_account()# Open Sheet
wb = gs.open("Sheet 1")
wb = wb.sheet1# fetch all rows
rows = wb.get_all_records()# fetch all columns
coloums = wb.get_all_values()# fetch specific row
row = wb.row_values(1)# fetch specific column
column = wb.col_values(1)# Get specific cell
cell = wb.cell(1,1).value# write to cell
wb.update_cell(3,2,"medium")

👉Weather API

Get Daily weather updates of any country or City by using below API code. The below-mentioned code uses the OpenWeatherMap API that allows you to fetch live weather updates of any location.

# Get API Key : <https://openweathermap.org/api>import requests
import jsonapi_key = 'YOUR_API_KEY'
city = 'London'
url = '<http://api.openweathermap.org/data/2.5/weather?q={}&appid={}'.format%28city,> api_key)
response = requests.get(url)data = response.json()
print(data)
print(data['weather'][0]['description'])
print(data['main']['temp'])
print(data['main']['pressure'])
print(data['main']['humidity'])

👉Fetch Movie Database

Need an API to fetch your Movies and tv Shows databases, Well this killer API will be handy for you. The API connects with the TheMovieDB website which holds a large database of movies and tv shows and it allows you to fetch popular movies, Best Tv shows, their rating, release date, etc.

# <https://www.themoviedb.org/documentation/api>
#  pip install tmdbv3apiimport tmdbv3api as mdbdb = mdb.TMDb()
db.api_key = 'API KEY'# get movies
mov = db.Movie()# get popular movies
movies = mov.popular()# get movie details
movies[0].id
movies[0].title
movies[0].overview
movies[0].vote_average# Get TV shows
tvShow = db.TV()
show = tvShow.search('Game of Thrones')
show[0].name
show[0].overview

👉OpenAI

This awesome API is based on machine learning applications. You can translate text, Make summarization, grammar corrections, and much more you can do with this API.

  • Grammar Correction
  • Translation
  • Recipe Creator
  • JavaScript to Python
  • Summarize Text
  • Much more
# Get your API : <https://beta.openai.com/>import openai as aiai.api_key = "Your API key"
text =  "Hey I hope you are doing great?"resp = ai.Completion.create(
  model="text-davinci-002",
  prompt=f"Translate this into 1. French:\n\n{text}\n\n1.",
  temperature=0.3,
  max_tokens=100,
  top_p=1.0,
)

👉URL Shortner API

Want to make your URL smaller then this API will be handy for you. This uses a free Bitly API that allows you to shorten any URL. Check out the code below:

# Get your API: <https://dev.bitly.com/>
# pip install bitly_apiimport bitly_apiapi_key = ""req = bitly_api.Connection(api_key)
url = "<https://medium.com/>"# Get the short url
short_url = req.shorten(url)
print(short_url)

👉 Do Calls and SMS

Working on a project in which you need assistance in sending SMS or doing calls then this API will be handy for you. It uses Twilio which allows you to send SMS and do outbound calls. Note: Twilio provide some free uses with credit. So you can take benefit with it.

# Get your API
# pip install twilioimport twilio.restacc = "API Key"
token = "API Token"
cli = twilio.rest.Client(acc, token)# Send SMS
msg = cli.messages.create(to="+xxxxxxxxxx", from_="+xxxxxxxxxx", body="Medium")# Do Programatic Calls
cli.calls.create(to="+xxxxxxxxxx", from_="+xxxxxxxxxx", twiml='<Response><Say> Medium </Say></Response>',)

👉Pokemon API

Get your favorite pokemon data programmatically by using this API. This cool API will let you fetch Pokemon data like its color, ability, name, Form, Gender, and much more.

# pip install requestsimport requestsapi_url = "<https://pokeapi.co/api/v2/pokemon/>"params = {"limit": "150"}
headers = {}res = requests.request("GET", api_url, headers=headers, params=params)data = res.json()
for pokemon in data["results"]:
    print(pokemon["name"])

👉Fetch Food Recipe

Use this API to fetch your favorite food recipe or extract ingredients from the recipe text. This API connects you with the Spoonacultar website that allows you to get the recipe, create a recipe from instructions, and much more.

# Get Your API : <https://spoonacular.com/>
# pip install spoonacularimport spoonacular as sprecipe = sp.API('Your Api Key')# Get Recipe info
recipe.get_recipe_information(id = 'recipe_id')# Get Ingredients
ingredients = recipe.parse_ingredients("5.25 cups flour")
print(ingredients)# Display Food Joke
res = recipe.get_a_random_food_joke()
joke = res.json()['text']
print(joke)# Get Random Recipe
res = recipe.get_a_random_recipe()
recipe = res.json()['recipes'][0]
print(recipe)

👉 Final thoughts

Well, I hope you find some useful APIs for your next Python Project. If you love this article then don’t forget to share ❤️ it with your friends because sharing is caring.

Happy Python Coding




Continue Learning