The usual way to read a subreddit from code is to register an app, request an OAuth token, refresh it before it expires, and send a descriptive User-Agent with every call. That is a lot of setup when all you want is the latest posts from r/learnpython and what people said under them. The shortcut is to scrape the HTML, which breaks the next time the markup changes.
This guide skips both. You will use two SteadyAPI Reddit endpoints with one API key, no Reddit app and no token handling, to list a subreddit's posts, page through them, and save each post with its comments to a JSONL file.
Prerequisites
- A SteadyAPI API key from steadyapi.com. The Free plan works for a small test; check the cost section before you scale up.
- Python 3.8+ with
requests.
The two calls
GET /v1/reddit/posts (weight 2) lists a subreddit's posts. Send subreddit (the name without r/) or a full url, and a sortType of hot, new, top or rising. Each page holds up to 25 posts. The response meta.cursor is the value to send back as cursor for the next page, and it is null when there are no more.
GET /v1/reddit/post (weight 1) returns one post and its comments. Send the full post URL as url. The post data is in body.post, and the comments are in body.post_comments.
A trimmed listing request looks like this:
curl "https://api.steadyapi.com/v1/reddit/posts?subreddit=learnpython&sortType=hot" \
-H "Authorization: Bearer YOUR_STEADYAPI_KEY"
{
"meta": { "version": "v1.0", "status": 200, "total": 25, "cursor": "t3_1xrjuxm" },
"body": [
{
"id": "1xsdgcg",
"title": "Question for the British python developers",
"author": "inobody_somebody",
"score": 157,
"created_utc": 1794284389,
"permalink": "/r/learnpython/comments/1xsdgcg/question_for_the_british_python_developers/",
"selftext": "This is a constructor, \\_\\_init\\_\\_?"
}
]
}
Each item is Reddit's own post object, so you will see many more fields than these. Use the ones you need.
The scraper
The script lists two pages of hot posts, picks the five with the highest scores, fetches the comments for each, and writes one JSON line per post.
import html
import json
import os
import sys
import time
import requests
BASE = "https://api.steadyapi.com"
API = f"{BASE}/v1/reddit"
HEADERS = {"Authorization": f"Bearer {os.environ['STEADYAPI_KEY']}"}
def call(path, **params):
for attempt in range(3):
r = requests.get(f"{API}/{path}", headers=HEADERS, params=params, timeout=60)
if r.status_code in (429, 500, 502, 503):
time.sleep(2 ** attempt)
continue
r.raise_for_status()
data = r.json()
if data.get("success") is False:
raise ValueError(data["message"])
return data
raise RuntimeError(f"{path} failed after retries")
def listing(subreddit, sort="hot", pages=2):
"""Yield posts from a subreddit feed, following meta.cursor."""
cursor = None
for _ in range(pages):
params = {"subreddit": subreddit, "sortType": sort}
if cursor:
params["cursor"] = cursor
data = call("posts", **params)
yield from data["body"]
cursor = data["meta"]["cursor"]
if not cursor:
break
def comments(permalink):
"""Return the comments the API gives back for one post."""
data = call("post", url="https://www.reddit.com" + permalink)
return [
{
"id": c["id"],
"author": c["author"],
"created_utc": c["created_utc"],
"text": c["content"],
}
for c in data["body"]["post_comments"]
]
def scrape(subreddit, sort="hot", pages=2, top_n=5, out="posts.jsonl"):
posts = [p for p in listing(subreddit, sort, pages) if not p.get("stickied")]
# Some items arrive without a score, so rank only the ones that have one.
scored = [p for p in posts if p.get("score") is not None]
chosen = sorted(scored, key=lambda p: p["score"], reverse=True)[:top_n]
with open(out, "w", encoding="utf-8") as f:
for p in chosen:
record = {
"id": p["id"],
"title": html.unescape(p["title"]),
"author": p["author"],
"score": p["score"],
"created_utc": p["created_utc"],
"url": "https://www.reddit.com" + p["permalink"],
"text": p.get("selftext", ""),
"comments": comments(p["permalink"]),
}
f.write(json.dumps(record) + "\n")
print(f"{record['score']:>5} pts {len(record['comments']):>3} comments {record['title'][:60]}")
print(f"\n{len(posts)} posts listed, {len(chosen)} saved to {out}")
if __name__ == "__main__":
scrape(sys.argv[1] if len(sys.argv) > 1 else "learnpython")
Run it with STEADYAPI_KEY=your_key python scrape.py learnpython. This is real output from a test run:
157 pts 23 comments Question for the British python developers
29 pts 23 comments Is Python a good choice for backend development?
24 pts 23 comments Are f-strings enough?
11 pts 14 comments Gift ideas for beginner coder
7 pts 2 comments I'm from a non-IT background and have been learning Python.
49 posts listed, 5 saved to posts.jsonl
Each line of posts.jsonl is one post with its comments in a list, so you can load it with json.loads line by line, or pass it to pandas with lines=True.
What comes back in the comments
Know the shape before you build on it. In my tests:
- Comments are a flat list of top-level comments. Each has
id,author,created_utcandcontent. Thereplieslist was empty, so do not expect a full nested thread. - Not every comment comes back. A thread with 42 comments returned 24, and one with 14 returned all 14.
meta.totalCommentstells you how many came back. Compare it with the post'snum_commentswhen that field is present. - Comment
score,up_votesandlikescame back as empty strings. Do not rank comments by them. - Some listing items are thin. A share of the posts in a listing arrived with
scoreandnum_commentsset tonull, which is why the script ranks only posts that have a score.
If your project needs complete nested threads or comment scores, check the current response for your target posts before you commit to this design. For summarizing a conversation, analyzing wording, or collecting questions, the top-level comments are usually enough.
Handle errors and edge cases
- An unknown subreddit returns HTTP 200. The body is
{"success": false, "message": "Please enter a valid subReddit URL."}. The script checkssuccessand raises. - Missing parameters return 422.
postsneedssubredditorurl, plussortType(or its aliasfilter). A 422 does not count toward your quota. - Titles contain HTML entities. An ampersand arrives as
&, so run titles throughhtml.unescape. - Responses are cached for about 15 minutes. Running the same request twice in a row returns the same data. Poll less often than that.
Best practices for cost and speed
One run of this script costs 9 requests: 2 listing pages at 2 each, plus 5 threads at 1 each. Raising top_n adds 1 request per extra post. The Free plan's 500 requests a month covers about 55 runs of this size. The Starter plan ($14.99/mo, 10,000 requests) covers roughly 1,100 runs of this size. The standard rate limit is 10 requests per second per account, and only HTTP 200 responses count toward your quota.
- Save what you fetch. Store posts by
idand skip any post you already have comments for. - Fetch comments only for posts that matter. The listing is 2 requests per page, but every thread is another request.
- Use
newfor monitoring andtoporhotfor research. In my teststopreturned only a short recent window, so it is not an all-time ranking.
Bonus: look at a subreddit by asking
If you use Claude Code, Cursor, VS Code, or any MCP client, you can connect it to https://api.steadyapi.com/mcp with your API key. Then you can ask what is hot in a subreddit in plain English, before you write any code.
Conclusion
You listed a subreddit's posts, followed the cursor to the next page, pulled the comments for the best ones, and saved everything as JSONL, without registering a Reddit app or managing tokens.
Create a free account at steadyapi.com (no card required) and point the script at a subreddit you follow. The API documentation lists every Reddit parameter with ready-made examples in cURL, JavaScript, PHP, and Python.