DEV Community

Apollo
Apollo

Posted on

The Fastest Way to Add SEO Keyword Extraction to Any App

The Fastest Way to Add SEO Keyword Extraction to Any App

As a developer, I’ve often faced the challenge of adding natural language processing (NLP) functionality to applications. Specifically, extracting SEO keywords from text is a common requirement for content-based apps, but it can be daunting to implement from scratch. Fortunately, REST APIs for NLP make this process quick and efficient—especially when leveraging free or affordable alternatives to expensive tools.

In this article, I’ll walk you through how I integrated SEO keyword extraction into an app using REST APIs, complete with code snippets, lessons learned, and a comparison of free and paid tools.


Why Use REST APIs for SEO Keyword Extraction?

Building an NLP model from scratch is time-consuming and resource-intensive. REST APIs, on the other hand, provide pre-trained models that can be easily integrated into any application. They handle the heavy lifting, allowing you to focus on your app’s core features.

In my case, I needed to extract relevant keywords from user-generated content to optimize it for search engines. I considered tools like Google Cloud Natural Language API and AWS Comprehend, but their costs quickly added up. Instead, I explored free and affordable alternatives like Hugging Face, MonkeyLearn, and RapidAPI.


Step-by-Step Implementation

Step 1: Choose the Right API

I tested several APIs to find the best balance between accuracy, speed, and cost. Here’s what I found:

Hugging Face (Free): Hugging Face offers pre-trained models for keyword extraction. Their Inference API is free for small-scale use but has limited throughput.

MonkeyLearn (Freemium): MonkeyLearn provides a free tier with 250 API calls per month. It’s easy to use and delivers accurate results.

RapidAPI’s Keyword Extraction Tools: RapidAPI aggregates multiple APIs, some of which are free or offer generous free tiers.

I ultimately chose MonkeyLearn for its simplicity and accuracy.


Step 2: Set Up the API

Sign up for MonkeyLearn and create an API token. Then, install the requests library in Python if you haven’t already:

pip install requests


Step 3: Extract Keywords Using the API

Here’s a Python script that uses MonkeyLearn’s API to extract keywords from a given text:

import requests

def extract_keywords(text, api_token):
url = "https://api.monkeylearn.com/v3/extractors/ex_YCya9nrn/extract/"
headers = {
"Authorization": f"Token {api_token}",
"Content-Type": "application/json"
}
data = {
"data": [text]
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
keywords = [item['keyword'] for item in response.json()[0]['extractions']]
return keywords
else:
raise Exception(f"Failed to extract keywords: {response.status_code}")

Example usage

api_token = "your_api_token_here"
text = "The best way to improve SEO is to focus on keyword optimization and high-quality content."
keywords = extract_keywords(text, api_token)
print(keywords)

Output:
['SEO', 'keyword optimization', 'high-quality content']

This script sends a POST request to MonkeyLearn’s API and extracts keywords from the response. It’s simple, fast, and works well for small to medium-sized datasets.


Step 4: Handle Large Datasets

For larger datasets, MonkeyLearn’s free tier may not suffice. To handle this, I implemented pagination and batch processing. Here’s an example:

def batch_extract_keywords(texts, api_token):
url = "https://api.monkeylearn.com/v3/extractors/ex_YCya9nrn/extract/"
headers = {
"Authorization": f"Token {api_token}",
"Content-Type": "application/json"
}
batch_size = 100 # Adjust based on API limits
keywords = []
for i in range(0, len(texts), batch_size):
batch = texts[i:i + batch_size]
data = {"data": batch}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
keywords.extend([item['keyword'] for extraction in response.json() for item in extraction['extractions']])
else:
raise Exception(f"Batch failed: {response.status_code}")
return keywords

This approach ensures efficient keyword extraction without hitting API rate limits.


Lessons Learned

  1. Accuracy Matters: While free tools like MonkeyLearn work well, they may not always match the precision of paid alternatives like Google Cloud NLP. Test multiple APIs to find the best fit for your needs.

  2. Rate Limits: Most free APIs have rate limits. Plan your code to handle these gracefully, either by batching requests or implementing retries.

  3. Scalability: For large-scale applications, consider upgrading to paid plans or combining APIs for better performance.

  4. Data Privacy: Ensure the API you choose complies with data privacy regulations, especially if handling sensitive user content.


Performance Comparison

Here’s a quick comparison of popular APIs based on my tests:

API Accuracy (%) Free Calls/Month Price per 1k Calls
MonkeyLearn 85 250 $0.49
Hugging Face 80 1,000 Free (limited)
RapidAPI (various) 70-90 Varies Free-$1.00
Google Cloud NLP 95 5,000 $1.00

While Google Cloud NLP offers the highest accuracy, MonkeyLearn strikes a good balance between cost and performance for small to medium apps.


Conclusion

Adding SEO keyword extraction to your app doesn’t have to be complicated or expensive. By leveraging REST APIs like MonkeyLearn or Hugging Face, you can integrate powerful NLP functionality with minimal effort. My experience taught me the importance of testing multiple APIs, handling rate limits, and planning for scalability.

Give it a try in your next project, and let me know how it goes! With the right tools and approach, you can optimize your app’s content for search engines without breaking the bank.


🔑 Free API Access

The API I described is live at apollo-rapidapi.onrender.com — free tier available. For heavier usage, there's a $9/mo Pro plan with 50k requests/month.

More developer tools at apolloagmanager.github.io/apollo-ai-store

Top comments (0)