Search Reddit posts across all subreddits and get JSON with score, comment count, flair and body text. Built on the Scrapier API: one HTTPS request, no headless browser to run, no parser to maintain.
Quickstart · Fields · CLI · FAQ
-
Get an API key from the Scrapier dashboard. No credit card needed to start.
-
Install:
pip install git+https://github.com/get-scrapier/Reddit-Search-Scraper
-
Run:
from scrapier_reddit_post_search import RedditPostSearch
client = RedditPostSearch(api_key="sk_live_...") # or set SCRAPIER_API_KEY
for post in client.iter_post_search("programming",
time_filter="all",
sort_by="top",
max_items=100):
# "comments" is a count, not a list
print(post["score"], post["comments"],
post["subreddit"], post["title"][:50])The same code is in examples/quickstart.py.
- Brand mention monitoring
- Market research
- Sentiment analysis
- Content ideas
Searches Reddit's posts for a keyword and walks the results with the score, the comment count, the flair and the body text.
Rows here are flatter and more complete than
scrapier-reddit-subreddit-search returns -- no hydration step, no
nesting.
Wraps the reddit-post-search endpoint, 25 rows a page.
# 1. A list. For scripts and one-liners.
rows = client.post_search(query, max_items=100)
# 2. A generator. Streams, so you can stop early and stop paying.
for row in client.iter_post_search(query):
handle(row)
# 3. A page at a time. You hold the cursor, so you can resume later.
page = client.post_search_page(query)
save(page.items)
while page.has_more:
page = client.post_search_page(cursor=page.next_cursor)
save(page.items)A Page carries the rows plus the envelope:
page.items # the rows
page.next_cursor # opaque string, or None
page.has_more # bool
page.raw_responses # upstream payloads, when raw_data=True
page.data # the whole envelope
len(page) # number of rowsObserved on live responses, not copied from a schema.
| Field | Notes |
|---|---|
post_id, name, permalink, url, link_url |
identity |
title, selftext |
the text |
score, votes, upvote_ratio |
the vote figures -- score and votes agree |
comments |
a count, not a list -- see the quirks |
author, author_id |
who posted it |
subreddit, subreddit_icon, subreddit_subscribers |
where it was posted |
flair |
the post's flair |
domain, media_type, is_self |
what kind of post |
nsfw, spoiler, locked, archived |
content and state flags |
created_time |
when |
input_query, page, position, type |
request metadata |
| Argument | What it does |
|---|---|
sort_by |
How to order the matches. Defaults to comments, which surfaces discussion rather than upvotes. |
time_filter |
The window to search. Defaults to year, so recent results unless you widen it. |
subreddit |
Limit the search to one subreddit. Omit it to search all of Reddit. |
page_size |
Posts per request, 1 to 100. Defaults to 25. |
comments is a number, not the comments. It is the comment count;
iterating it will not do what you expect. For the actual comments use
scrapier-reddit-comments with the post's URL.
time_filter defaults to year. A search without it silently
excludes anything older, which matters when you are looking for a
historical discussion.
sort_by defaults to comments, not relevance or score -- so
the default results are the most-discussed rather than the
best-matching.
locked and archived matter for sentiment work: a locked
thread stopped accepting comments, and Reddit archives old posts, so
neither will have grown since.
This endpoint has no bulk-job form -- no Celery task behind it -- so
there is no bulk() method here.
Each page is a billable request, so bound a broad walk:
client.post_search(query, max_items=200) # stop after 200 rows
client.post_search(query, max_pages=5) # stop after 5 requestsmax_items truncates mid-page rather than buying another page to fill a
quota. Checking your balance is free:
print(client.credits())
print(client.account())AsyncRedditPostSearch exposes every method RedditPostSearch does,
with identical arguments.
import asyncio
from scrapier_reddit_post_search import AsyncRedditPostSearch
async def main():
async with AsyncRedditPostSearch() as client:
rows = await client.post_search(query)
asyncio.run(main())This endpoint has no job form on the server, so there is no bulk()
method. Page through with max_items instead.
Everything derives from ScrapierError, so one except can catch the
lot while you still get to be specific when it matters.
from scrapier_reddit_post_search import InsufficientCreditsError, RateLimitError, ScrapierError
try:
rows = client.post_search(query)
except InsufficientCreditsError as exc:
print(f"out of credits: {exc.balance} left, {exc.required} needed")
except RateLimitError as exc:
print(f"slow down for {exc.retry_after}s")
except ScrapierError as exc:
print(f"something else: {exc}")| Exception | When |
|---|---|
ConfigurationError |
no API key, or a reserved parameter was passed |
TransportError |
the request never got a response |
BadRequestError |
400 — bad input |
AuthenticationError |
401 — bad or missing key |
InsufficientCreditsError |
402 with a balance — carries .balance and .required |
NotFoundError |
404 |
RateLimitError |
429 — carries .retry_after |
ScrapeTimeoutError |
504 — the scrape itself ran out of time |
ServiceUnavailableError |
503 |
ServerError |
5xx |
JobFailedError |
a bulk job finished in failed — carries .errors |
APIError |
the base for anything with a status code |
429, 503, 5xx and transport failures are retried automatically with
jittered backoff that honours Retry-After. 400, 401, 404 and a 402
about your balance are not — retrying those only wastes time.
export SCRAPIER_API_KEY=sk_live_...
scrapier-reddit-post-search <query> --max-items 50 --jsonlJSON on stdout and nothing else, so it pipes. Global flags (--api-key,
--base-url, --timeout, --jsonl, --indent) work anywhere on the
line. Exit codes: 0 success, 2 usage or configuration, 3 API
error.
RedditPostSearch(
api_key=None, # falls back to $SCRAPIER_API_KEY
base_url=None, # falls back to $SCRAPIER_BASE_URL, then the default
timeout=150.0,
max_retries=3, # for 429/503/5xx and transport failures
http_client=None, # bring your own httpx.Client
)The key is sent in the X-API-Key header only — never in a URL or a
request body, so it will not end up in a proxy log.
Every call also accepts method="GET" if you would rather the
parameters went in the query string, use_proxy=True to route the
scrape through Scrapier's proxy pool, and raw_data=True to get the
upstream payloads instead of parsed rows.
Python 3.9+. The only dependency is httpx. Ships py.typed.
The client code is MIT-licensed. It needs a Scrapier API key, and requests are billed in credits; failed requests are not billed. See pricing. You can start without a credit card.
No. The scrape runs on Scrapier's servers and returns JSON.
This endpoint has no bulk form. Loop over your inputs, or use the async client.
Yes. See AGENTS.md, or connect the
Scrapier MCP server.
180+ endpoints across 35+ platforms: browse them all.
Open an issue or read the docs.
MIT. See LICENSE.