FastAPI proxy for Reddit's JSON API, modeled on Redlib. Works anonymously without a Reddit account.
- Safari TLS impersonation (
curl_cffi): Reddit returns 403 ("Blocked by network security") to standard HTTP clients (httpx,curl, Chrome/Firefox/OkHttp TLS fingerprints). Requests run through a SafariAsyncSessionand reroll the Safari profile on fingerprint 403s. - Anonymous OAuth:
POST /auth/v2/oauth/access-token/loidwith Android device headers (x-reddit-loid,x-reddit-session). If that fails, falls back to solvingwww.reddit.com's JS challenge for atoken_v2cookie. - GraphQL over HTTP/1.1 (
gql.py): Comments, user profiles/listings, and search are blocked on anonymous*.jsoneven with a valid token. Those routes hithttps://gql-fed.reddit.com/over HTTP/1.1 (HTTP/2 returns 403) and map the response to Reddit's JSON shape. - Fallbacks: Retries with backoff on 429/5xx, refreshes token on 401/403, falls through
oauth.reddit.com->www.reddit.com->old.reddit.com->REDDIT_COOKIE(if set) -> stale cache.
pip install -r requirements.txt
uvicorn main:app --reload --port 8080- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn main:app --host 0.0.0.0 --port $PORT - Environment variables (optional):
REDDIT_COOKIE(orREDLIB_REDDIT_COOKIE): Logged-inreddit_session=...cookie string (or barereddit_sessionvalue). Only used as a last-resort fallback if anonymous tiers fail (for example, if Reddit blocks a datacenter IP).- How to get it: Log into
reddit.comin a browser (use a throwaway account, and don't click Log out afterwards), open DevTools → Application / Storage → Cookies →https://www.reddit.com, and copy thereddit_sessionvalue.
- How to get it: Log into
| Route | Description |
|---|---|
GET /health |
Health check |
GET /r/{subreddit}/{sort} |
Subreddit listing (hot, new, top, rising, controversial) |
GET /r/{subreddit}/comments/{post_id} |
Post + comment tree |
GET /comments/{post_id} |
Post + comment tree (short form) |
GET /user/{username}/about |
User profile info |
GET /user/{username} |
Combined user info + listing (sort, limit, after) |
GET /user/{username}/{sort} |
User listing (overview, submitted, comments, upvoted, gilded) |
GET /search?q=...&subreddit=... |
Search, optionally scoped to a subreddit |
GET /best |
Front page listing |
GET /raw/{path} |
Passthrough for any Reddit JSON path |
config.py—ANDROID_CLIENT_IDS, Safari profiles, Android device/UA lists,REDDIT_COOKIE, timing constantscache.py— In-memory TTL cache (fresh + stale reads, single-process)gql.py— Persisted GraphQL queries (gql-fed.reddit.com) and JSON shapingreddit_client.py—curl_cffisession, OAuth flows, fallback chainmain.py— FastAPI routes