Module 2: Consuming Data from an API

Module Overview

A powerful way to enhance a web application is by connecting it to an API. These Application Programming Interfaces accept requests and return results, similar to the servers you build with Flask. What makes APIs powerful is the breadth of data they provide—from tweets to weather to space imagery to Pokémon—enabling your applications to leverage rich, real-world information.

Learning Objectives

Objective 01 - Connect to the Twitter API and query for tweets by various parameters

Overview

API stands for Application Programming Interface, a specification for how components of an application can communicate and share/cooperate. You can think of it as a contract - by having an API, anybody who works with the system knows what to expect and what they should do to get desired results.

One of the main original APIs was for graphical programs - Windows exposes an API for interacting with the underlying operating system, which Windows desktop apps must use to behave as expected.

These days the term API usually references third party APIs accessed over the web. In some cases, you will work with a true API, but you could also call it “somebody else's database”.

Follow Along

Twitter is changing their API policies and tweepy is going offline very soon. In its place, we have implemented a Twitter-API-like clone and an API interface library to bridge the gap. We named the Twitter API "NotTwitter" and the library "NotTweepy".

To install NotTweepy copy the folder not_tweepy into your local repo at the root level of your project.

You will find the folder in the GitHub repository for the Unit here

You may follow the instructions in this Guided Project video with the only exception:

When you see:

import tweepy

You will instead type:

import not_tweepy as tweepy

NotTwitter has been prepopulated with tweets from the following users:

Guided Project

Open guided-project.md in the GitHub repository to follow along with the guided project.

Due to recent changes in the accessibility of the Twitter API, you will no longer need to request Twitter API keys. Please refer to the information below for instructions.

Twitter is changing their API policies and tweepy is going offline very soon. In its place, we have implemented a Twitter-API-like clone and an API interface library to bridge the gap. We named the Twitter API "NotTwitter" and the library "NotTweepy".

To install NotTweepy, copy the folder not_tweepy into your local repo at the root level of your project.

  • Project
    • twitoff
    • not_tweepy

You will find the folder in the GitHub repository for the Unit here.

You may follow the instructions in this Guided Project video with the only exception:

When you see:

import tweepy

You will instead type:

import not_tweepy as tweepy

NotTwitter has been prepopulated with tweets from the following users:

  • calebhicks
  • elonmusk
  • rrherr
  • SteveMartinToGo
  • alyankovic
  • NASA
  • jkhowland
  • Austen
  • common_squirrel
  • KenJennings
  • ConanOBrien
  • big_ben_clock
  • IAM_SHAKESPEARE

Module Assignment

Ensure you can access the Twitter API and SpaCy package, then write methods to pull real Users and Tweets, replacing invented data with actual Twitter data, and add a tweet_vect field to your Tweet model using SpaCy embeddings.

Assignment Solution Video

Additional Resources

Current Tools

Background Reading