FetchLayer fetchlayer.dev Sign in

+ Integration Guide

Reddit Scraping API with Python: Complete Guide

How to scrape Reddit with Python using the FetchLayer API. Search posts, scrape comments, and monitor subreddits — no PRAW or Reddit credentials needed.

  • Python
  • reddit scraping
  • reddit API
  • PRAW alternative
  • API integration

This guide shows how to use the FetchLayer Reddit API with Python. Unlike PRAW, you don’t need Reddit credentials, OAuth setup, or a Reddit account. Just an API key and the requests library.


Setup

  1. Get a free API key (no credit card)
  2. Install requests: pip install requests

API Client

import os
import requests

API_KEY = os.environ["FETCHLAYER_API_KEY"]
BASE_URL = "https://fetchlayer.dev/api/reddit"

def reddit(endpoint: str, **kwargs) -> dict:
    res = requests.post(
        f"{BASE_URL}/{endpoint}",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json=kwargs,
    )
    res.raise_for_status()
    return res.json()

Search Reddit

data = reddit("search", query="best Python web framework", sort="top", limit=10)

for post in data["results"]:
    print(f"[{post['score']}] {post['title']} — r/{post['subreddit']}")
# Search within a specific subreddit
data = reddit("search", query="FastAPI vs Django", subreddit="Python", sort="relevance")

Get Subreddit Posts

data = reddit("community-posts", subreddit="Python", sort="top", time="week", limit=20)

for post in data["posts"]:
    print(f"[{post['score']}] {post['title']}")

Scrape a Post with Comments

thread = reddit(
    "post",
    url="https://www.reddit.com/r/Python/comments/abc123/some_post/",
    pages=2,
)

print(f"{thread['title']}{len(thread['comments'])} comments")

for comment in thread["comments"][:5]:
    print(f"  {comment['author']}: {comment['body'][:100]}...")

Get User Profile

profile = reddit("user-profile", username="spez")

print(f"{profile['username']}{profile['totalKarma']} karma — {profile['accountAge']}")

PRAW vs FetchLayer

If you’re coming from PRAW, here’s the comparison:

PRAWFetchLayer
Reddit account requiredYesNo
OAuth setupYes (+ app registration, can be rejected)No
Rate limits100 req/min OAuth / 10 req/min unauthHandled by API
Commercial useEnterprise contract required (~$12K/yr min)Free tier + pay-per-use
Historical dataNoYes
LanguagePython onlyAny (REST API)
MCP supportNoYes
AuthenticationClient ID + secretSingle API key

PRAW equivalent vs FetchLayer:

# PRAW (requires Reddit credentials)
import praw
reddit_client = praw.Reddit(client_id="...", client_secret="...", user_agent="...")
for post in reddit_client.subreddit("Python").hot(limit=10):
    print(post.title)

# FetchLayer (just an API key)
data = reddit("community-posts", subreddit="Python", sort="hot", limit=10)
for post in data["posts"]:
    print(post["title"])

Full Example: Sentiment Monitor

import os
import requests
from collections import Counter

API_KEY = os.environ["FETCHLAYER_API_KEY"]
BASE_URL = "https://fetchlayer.dev/api/reddit"

def reddit(endpoint: str, **kwargs) -> dict:
    res = requests.post(
        f"{BASE_URL}/{endpoint}",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json=kwargs,
    )
    res.raise_for_status()
    return res.json()

def monitor_keyword(keyword: str, subreddits: list[str]):
    """Search for a keyword across subreddits and summarize results."""
    all_posts = []

    for sub in subreddits:
        data = reddit("search", query=keyword, subreddit=sub, sort="new", limit=10)
        for post in data.get("results", []):
            post["_subreddit"] = sub
            all_posts.append(post)

    # Sort by score
    all_posts.sort(key=lambda p: p["score"], reverse=True)

    # Summary
    subreddit_counts = Counter(p["_subreddit"] for p in all_posts)

    print(f"\nFound {len(all_posts)} posts for '{keyword}'")
    print(f"Top subreddits: {dict(subreddit_counts.most_common(5))}")
    print(f"\nTop 5 posts:")

    for post in all_posts[:5]:
        print(f"  [{post['score']}] {post['title']}")
        print(f"  r/{post['_subreddit']}{post.get('numComments', 0)} comments")
        print(f"  {post['url']}\n")

if __name__ == "__main__":
    monitor_keyword(
        "your-product-name",
        ["startups", "SaaS", "webdev", "Python", "programming"]
    )
FETCHLAYER_API_KEY=sk-your-key python monitor.py

What’s Next