0
# Live Threads
1
2
PRAW provides comprehensive support for Reddit Live Threads, which enable real-time event coverage and collaborative updates. Live threads are perfect for breaking news, sports events, AMAs, and any situation requiring real-time community updates.
3
4
## Capabilities
5
6
### LiveHelper - Live Thread Management
7
8
Create and discover live threads across Reddit.
9
10
```python { .api }
11
class LiveHelper:
12
def __init__(self, reddit): ...
13
14
def create(
15
self,
16
title: str,
17
*,
18
description: str = None,
19
nsfw: bool = False,
20
resources: str = None,
21
**kwargs
22
):
23
"""
24
Create a new live thread.
25
26
Parameters:
27
- title: Live thread title
28
- description: Thread description (markdown supported)
29
- nsfw: Whether thread contains NSFW content
30
- resources: Resource links or information
31
32
Returns:
33
LiveThread instance
34
"""
35
36
def info(self, ids: list):
37
"""
38
Get information about live threads by ID.
39
40
Parameters:
41
- ids: List of live thread IDs
42
43
Returns:
44
Generator of LiveThread instances
45
"""
46
47
def now(self):
48
"""
49
Get currently happening live threads.
50
51
Returns:
52
Generator of active LiveThread instances
53
"""
54
```
55
56
### LiveThread - Live Thread Operations
57
58
Manage individual live threads including updates, contributors, and settings.
59
60
```python { .api }
61
class LiveThread:
62
def __init__(self, reddit, id: str = None): ...
63
64
def contributor(self):
65
"""
66
Get LiveThreadContribution instance for managing contributors.
67
68
Returns:
69
LiveThreadContribution instance
70
"""
71
72
def discussions(self, **kwargs):
73
"""
74
Get discussions (linked submissions) for this live thread.
75
76
Parameters:
77
- limit: Number of discussions (default: 25, max: 100)
78
- params: Additional query parameters
79
80
Returns:
81
ListingGenerator of Submission instances
82
"""
83
84
def updates(self, **kwargs):
85
"""
86
Get live updates from this thread.
87
88
Parameters:
89
- limit: Number of updates (default: 25, max: 100)
90
- params: Additional query parameters
91
92
Returns:
93
ListingGenerator of LiveUpdate instances
94
"""
95
96
def add_update(self, body: str):
97
"""
98
Add new update to live thread (requires contributor access).
99
100
Parameters:
101
- body: Update content (markdown supported)
102
103
Returns:
104
LiveUpdate instance
105
"""
106
107
def close_thread(self):
108
"""
109
Close the live thread (prevent new updates).
110
111
Only thread creators and certain contributors can close threads.
112
"""
113
```
114
115
### LiveThread Properties and Data
116
117
Access live thread metadata, status, and configuration.
118
119
```python { .api }
120
# Basic properties
121
id: str # Live thread ID (base36)
122
title: str # Thread title
123
description: str # Thread description
124
description_html: str # Description as HTML
125
state: str # Thread state ("live", "complete", etc.)
126
viewer_count: int # Current number of viewers
127
viewer_count_fuzzed: bool # Whether viewer count is fuzzed
128
129
# Content and activity
130
total_views: int # Total view count
131
num_updates: int # Number of updates posted
132
updates: list # List of LiveUpdate instances
133
134
# Timestamps
135
created_utc: float # Creation timestamp (UTC)
136
updated_utc: float # Last update timestamp (UTC)
137
138
# Configuration
139
nsfw: bool # Whether NSFW content
140
websocket_url: str # WebSocket URL for real-time updates
141
announcement_url: str # Announcement post URL
142
resources: str # Resource information
143
resources_html: str # Resources as HTML
144
145
# Status flags
146
is_announcement: bool # Whether this is an announcement thread
147
icon: str # Thread icon URL
148
mobile_banner_image: str # Mobile banner image URL
149
banner_image: str # Banner image URL
150
```
151
152
### LiveUpdate - Individual Updates
153
154
Manage individual updates within live threads.
155
156
```python { .api }
157
class LiveUpdate:
158
def __init__(self, live_thread, id: str = None): ...
159
160
def contrib(self):
161
"""
162
Get LiveUpdateContribution instance for this update.
163
164
Returns:
165
LiveUpdateContribution instance
166
"""
167
168
class LiveUpdateContribution:
169
"""Contributor actions for live updates."""
170
171
def remove(self):
172
"""Remove this live update (contributor only)."""
173
```
174
175
### LiveUpdate Properties and Data
176
177
Access individual update content and metadata.
178
179
```python { .api }
180
# Update content
181
id: str # Update ID
182
body: str # Update content
183
body_html: str # Update content as HTML
184
mobile_embeds: list # Mobile embed data
185
embeds: list # Embed data
186
187
# Author and timing
188
author: Redditor # Update author
189
created_utc: float # Creation timestamp (UTC)
190
name: str # Update fullname
191
192
# Status
193
stricken: bool # Whether update is struck through (deprecated)
194
```
195
196
### LiveThread Contribution Management
197
198
Manage contributors and permissions for live threads.
199
200
```python { .api }
201
class LiveThreadContribution:
202
"""Manage live thread contributors."""
203
204
def add(
205
self,
206
redditor,
207
*,
208
permissions: list = None
209
):
210
"""
211
Add contributor to live thread.
212
213
Parameters:
214
- redditor: Redditor instance or username
215
- permissions: List of permissions to grant
216
"""
217
218
def invite(
219
self,
220
redditor,
221
*,
222
permissions: list = None
223
):
224
"""
225
Invite user to contribute to live thread.
226
227
Parameters:
228
- redditor: Redditor instance or username
229
- permissions: List of permissions to grant
230
"""
231
232
def leave(self):
233
"""Leave as contributor from this live thread."""
234
235
def remove(self, redditor):
236
"""
237
Remove contributor from live thread.
238
239
Parameters:
240
- redditor: Redditor instance or username
241
"""
242
243
def remove_invite(self, redditor):
244
"""
245
Remove pending invitation.
246
247
Parameters:
248
- redditor: Redditor instance or username
249
"""
250
251
def update(
252
self,
253
redditor,
254
*,
255
permissions: list
256
):
257
"""
258
Update contributor permissions.
259
260
Parameters:
261
- redditor: Redditor instance or username
262
- permissions: New list of permissions
263
"""
264
265
def update_invite(
266
self,
267
redditor,
268
*,
269
permissions: list
270
):
271
"""
272
Update pending invitation permissions.
273
274
Parameters:
275
- redditor: Redditor instance or username
276
- permissions: New list of permissions
277
"""
278
279
def accept_invite(self):
280
"""Accept pending contributor invitation."""
281
```
282
283
### LiveThread Streaming
284
285
Real-time streaming of live thread updates.
286
287
```python { .api }
288
class LiveThreadStream:
289
"""Real-time live thread update streaming."""
290
291
def updates(self, **kwargs):
292
"""
293
Stream new updates from live thread.
294
295
Parameters:
296
- pause_after: Pause after this many requests
297
- skip_existing: Skip updates created before stream start
298
299
Yields:
300
LiveUpdate instances as they are posted
301
"""
302
303
stream: LiveThreadStream # Streaming instance
304
```
305
306
### Live Thread Permissions
307
308
Manage contributor permissions for live threads.
309
310
```python { .api }
311
# Available live thread permissions
312
LIVE_THREAD_PERMISSIONS = [
313
"update", # Post updates
314
"edit", # Edit thread settings
315
"manage" # Manage contributors
316
]
317
318
# Permission usage
319
def add_live_contributor():
320
live_thread.contributor.add(
321
"username",
322
permissions=["update"] # Can post updates only
323
)
324
325
live_thread.contributor.add(
326
"moderator",
327
permissions=["update", "edit", "manage"] # Full permissions
328
)
329
```
330
331
## Usage Examples
332
333
### Creating and Managing Live Threads
334
335
```python
336
import praw
337
338
reddit = praw.Reddit(...)
339
340
# Create a new live thread
341
live_thread = reddit.live.create(
342
title="Breaking News: Major Event Coverage",
343
description="Live coverage of the ongoing situation. Updates will be posted as information becomes available.",
344
nsfw=False,
345
resources="Official sources: [News Site](https://example.com)"
346
)
347
348
print(f"Created live thread: {live_thread.title}")
349
print(f"Thread ID: {live_thread.id}")
350
print(f"URL: https://www.reddit.com/live/{live_thread.id}")
351
352
# Add initial update
353
live_thread.add_update("**Live coverage starting now.** We'll be providing updates as the situation develops.")
354
355
# Update thread settings
356
live_thread.title = "Updated: Breaking News Coverage"
357
```
358
359
### Managing Contributors
360
361
```python
362
# Add contributors with different permission levels
363
live_thread = reddit.live("abc123")
364
365
# Add update-only contributor
366
live_thread.contributor.add(
367
"reporter1",
368
permissions=["update"]
369
)
370
371
# Add full contributor
372
live_thread.contributor.add(
373
"moderator1",
374
permissions=["update", "edit", "manage"]
375
)
376
377
# Invite contributors
378
live_thread.contributor.invite(
379
"reporter2",
380
permissions=["update"]
381
)
382
383
print("Contributors invited successfully")
384
385
# Accept invitation (as invited user)
386
live_thread.contributor.accept_invite()
387
388
# Remove contributor
389
live_thread.contributor.remove("reporter1")
390
```
391
392
### Posting Live Updates
393
394
```python
395
# Post regular updates
396
updates = [
397
"**10:30 AM:** Initial reports coming in...",
398
"**10:35 AM:** Confirmed by official sources.",
399
"**10:40 AM:** Emergency services on scene.",
400
"**10:45 AM:** Traffic being redirected around area."
401
]
402
403
for update_text in updates:
404
update = live_thread.add_update(update_text)
405
print(f"Posted update: {update.id}")
406
time.sleep(300) # Wait 5 minutes between updates
407
408
# Post update with embedded media
409
media_update = live_thread.add_update(
410
"**Live footage available:** [Video Link](https://example.com/video)\n\n"
411
"Emergency crews working to secure the area. More updates coming soon."
412
)
413
```
414
415
### Monitoring Live Threads
416
417
```python
418
# Get currently active live threads
419
print("Active live threads:")
420
for thread in reddit.live.now():
421
print(f"Title: {thread.title}")
422
print(f"Viewers: {thread.viewer_count}")
423
print(f"Updates: {thread.num_updates}")
424
print(f"State: {thread.state}")
425
print("---")
426
427
# Get specific thread by ID
428
thread = reddit.live("thread_id")
429
print(f"Thread: {thread.title}")
430
print(f"Description: {thread.description}")
431
432
# Get recent updates
433
print("Recent updates:")
434
for update in thread.updates(limit=10):
435
print(f"[{update.created_utc}] {update.author}: {update.body}")
436
```
437
438
### Real-time Update Streaming
439
440
```python
441
# Stream updates from specific live thread
442
live_thread = reddit.live("abc123")
443
444
print(f"Streaming updates from: {live_thread.title}")
445
for update in live_thread.stream.updates():
446
print(f"\nNew update by {update.author}:")
447
print(f"Time: {datetime.fromtimestamp(update.created_utc)}")
448
print(f"Content: {update.body}")
449
450
# Process the update
451
if "breaking" in update.body.lower():
452
print("⚠️ BREAKING NEWS UPDATE!")
453
454
# You can add your own processing logic here
455
# e.g., send notifications, update databases, etc.
456
457
# Stream from multiple live threads
458
active_threads = list(reddit.live.now())
459
for thread in active_threads:
460
print(f"Monitoring: {thread.title}")
461
# Set up streaming for each active thread
462
```
463
464
### Advanced Live Thread Management
465
466
```python
467
def manage_live_event():
468
"""Comprehensive live event management."""
469
470
# Create event thread
471
event_thread = reddit.live.create(
472
title="Sports Championship Live Coverage",
473
description="Live updates from the championship game.",
474
resources="Official scorer: [Link](https://example.com)\nStats: [Link](https://stats.example.com)"
475
)
476
477
# Set up contributor team
478
contributors = {
479
"main_reporter": ["update", "edit"],
480
"backup_reporter": ["update"],
481
"moderator": ["update", "edit", "manage"]
482
}
483
484
for username, permissions in contributors.items():
485
try:
486
event_thread.contributor.add(username, permissions=permissions)
487
print(f"Added {username} with permissions: {permissions}")
488
except Exception as e:
489
print(f"Failed to add {username}: {e}")
490
491
# Post scheduled updates
492
game_events = [
493
("Game starting", "⚽ Kickoff! The championship game is now underway."),
494
("First goal", "🥅 GOAL! Amazing shot gives the home team a 1-0 lead!"),
495
("Halftime", "⏰ Halftime break. Score remains 1-0."),
496
("Second half", "▶️ Second half underway!"),
497
("Final whistle", "🏆 FULL TIME! What an incredible match!")
498
]
499
500
for event_name, update_text in game_events:
501
event_thread.add_update(f"**{event_name.upper()}:** {update_text}")
502
print(f"Posted: {event_name}")
503
504
# In real usage, you'd wait for actual events
505
# time.sleep(actual_time_between_events)
506
507
# Close thread when event ends
508
event_thread.close_thread()
509
print("Event coverage complete - thread closed")
510
511
return event_thread
512
513
# Run event management
514
championship_thread = manage_live_event()
515
```
516
517
### Live Thread Analytics and Monitoring
518
519
```python
520
def analyze_live_thread(thread_id):
521
"""Analyze live thread performance and engagement."""
522
523
thread = reddit.live(thread_id)
524
525
print(f"Live Thread Analysis: {thread.title}")
526
print(f"Total Views: {thread.total_views:,}")
527
print(f"Current Viewers: {thread.viewer_count:,}")
528
print(f"Total Updates: {thread.num_updates}")
529
print(f"Thread State: {thread.state}")
530
531
# Analyze update frequency
532
updates = list(thread.updates(limit=100))
533
if updates:
534
update_times = [update.created_utc for update in updates]
535
time_diffs = [update_times[i] - update_times[i+1] for i in range(len(update_times)-1)]
536
537
if time_diffs:
538
avg_interval = sum(time_diffs) / len(time_diffs)
539
print(f"Average time between updates: {avg_interval/60:.1f} minutes")
540
541
# Contributor analysis
542
contributors = {}
543
for update in updates:
544
author = update.author.name if update.author else "[deleted]"
545
contributors[author] = contributors.get(author, 0) + 1
546
547
print("\nTop Contributors:")
548
for author, count in sorted(contributors.items(), key=lambda x: x[1], reverse=True)[:5]:
549
print(f" {author}: {count} updates")
550
551
# Get linked discussions
552
discussions = list(thread.discussions(limit=10))
553
print(f"\nLinked Discussions: {len(discussions)}")
554
for discussion in discussions:
555
print(f" r/{discussion.subreddit.display_name}: {discussion.title}")
556
557
# Analyze specific thread
558
analyze_live_thread("example_thread_id")
559
```
560
561
### Error Handling and Best Practices
562
563
```python
564
def robust_live_thread_management():
565
"""Live thread management with proper error handling."""
566
567
try:
568
# Create thread with validation
569
title = "Event Coverage"
570
if len(title) < 3:
571
raise ValueError("Title too short")
572
573
live_thread = reddit.live.create(
574
title=title,
575
description="Comprehensive event coverage with regular updates."
576
)
577
578
# Add updates with retry logic
579
def add_update_with_retry(content, max_retries=3):
580
for attempt in range(max_retries):
581
try:
582
return live_thread.add_update(content)
583
except Exception as e:
584
print(f"Attempt {attempt + 1} failed: {e}")
585
if attempt == max_retries - 1:
586
raise
587
time.sleep(2 ** attempt) # Exponential backoff
588
589
# Post updates safely
590
updates = [
591
"Event starting soon...",
592
"Updates will be posted regularly.",
593
"Thank you for following along!"
594
]
595
596
for i, update_content in enumerate(updates):
597
try:
598
update = add_update_with_retry(f"**Update {i+1}:** {update_content}")
599
print(f"Successfully posted update {i+1}")
600
except Exception as e:
601
print(f"Failed to post update {i+1}: {e}")
602
continue
603
604
return live_thread
605
606
except Exception as e:
607
print(f"Live thread management failed: {e}")
608
return None
609
610
# Use robust management
611
thread = robust_live_thread_management()
612
if thread:
613
print(f"Successfully created and managed thread: {thread.id}")
614
```
615
616
## Types
617
618
```python { .api }
619
class LiveThreadStream:
620
"""Real-time streaming for live threads."""
621
622
def updates(self, **kwargs):
623
"""Stream live updates as they are posted."""
624
625
class WebSocketException(Exception):
626
"""Raised when WebSocket operations fail."""
627
```