Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.65 KB

File metadata and controls

56 lines (40 loc) · 1.65 KB

Reddit Stream

Near-real-time Reddit posts via public Atom RSS feeds.

No credentials required.

Quick Start

uv run python examples/reddit_example.py

Usage

from streams.reddit import RedditStream

stream = RedditStream(subreddits=["python", "technology"])
await stream.start()

async for event in stream:
    post = event.payload
    print(f"Post: {post.title} in r/{post.subreddit}")

RedditPost Fields

Field Type Description
id str Reddit submission ID (e.g. abc123)
subreddit str Subreddit name
title str Post title
author str Username (without /u/ prefix)
permalink str Full reddit.com URL
description str HTML body / selftext excerpt
created_utc datetime Submission time (UTC)

How It Works

  • Polls /r/{subreddit}/new/.rss?limit=25 for each configured subreddit every 60 seconds
  • Deduplicates by post ID across polls — each post is emitted exactly once
  • Uses xml.etree.ElementTree (stdlib) to parse the Atom feed; no third-party Reddit library
  • When subreddits=None, streams from a built-in list of 100 tech/data/AI subreddits

Optional Configuration

# .env (optional — a sensible default is used automatically)
REDDIT_USER_AGENT=my-app/1.0 (contact@example.com)

Notes

  • Comments are not available via this approach (they require per-post API requests)
  • New posts typically appear within 60–120 seconds (one to two poll cycles)
  • Reddit may throttle anonymous RSS requests on busy subreddits; the client logs warnings and continues