or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

authentication.mdcontent-discovery.mdindex.mdlive-threads.mdmessaging-inbox.mdmoderation.mdreddit-client.mdsubmissions-comments.mdsubreddits.mduser-management.md

reddit-client.mddocs/

0

# Reddit Client

1

2

The Reddit class serves as the main entry point for all PRAW functionality. It handles authentication, manages API requests, and provides access to all Reddit features through helper objects and direct methods.

3

4

## Capabilities

5

6

### Client Initialization

7

8

Create a Reddit instance with various authentication methods and configuration options.

9

10

```python { .api }

11

def __init__(

12

self,

13

site_name: str = None,

14

config_interpolation: str = None,

15

requestor_class = None,

16

requestor_kwargs: dict = None,

17

token_manager = None,

18

**config_settings

19

):

20

"""

21

Initialize Reddit instance.

22

23

Parameters:

24

- site_name: Configuration site name from praw.ini

25

- client_id: OAuth client ID

26

- client_secret: OAuth client secret

27

- user_agent: User agent string (required)

28

- username: Reddit username (for script auth)

29

- password: Reddit password (for script auth)

30

- refresh_token: OAuth refresh token

31

- redirect_uri: OAuth redirect URI

32

- config_interpolation: Configuration interpolation method

33

- requestor_class: Custom requestor class

34

- requestor_kwargs: Requestor configuration

35

- token_manager: Custom token manager

36

"""

37

```

38

39

**Usage Examples:**

40

41

```python

42

# Script authentication

43

reddit = praw.Reddit(

44

client_id="your_client_id",

45

client_secret="your_client_secret",

46

username="your_username",

47

password="your_password",

48

user_agent="MyBot v1.0 by /u/username"

49

)

50

51

# Web application authentication

52

reddit = praw.Reddit(

53

client_id="your_client_id",

54

client_secret="your_client_secret",

55

redirect_uri="http://localhost:8080",

56

user_agent="MyApp v1.0 by /u/username"

57

)

58

59

# Read-only mode

60

reddit = praw.Reddit(

61

client_id="your_client_id",

62

client_secret="your_client_secret",

63

user_agent="MyApp v1.0 by /u/username"

64

)

65

reddit.read_only = True

66

```

67

68

### Direct Content Access

69

70

Access specific Reddit content directly by ID or URL.

71

72

```python { .api }

73

def comment(self, id: str | None = None, *, url: str | None = None):

74

"""

75

Return a lazy Comment instance.

76

77

Parameters:

78

- id: Comment ID (base36)

79

- url: Comment URL

80

81

Returns:

82

Comment instance

83

"""

84

85

def submission(self, id: str | None = None, *, url: str | None = None):

86

"""

87

Return a lazy Submission instance.

88

89

Parameters:

90

- id: Submission ID (base36)

91

- url: Submission URL

92

93

Returns:

94

Submission instance

95

"""

96

97

def redditor(self, name: str | None = None, *, fullname: str | None = None):

98

"""

99

Return a lazy Redditor instance.

100

101

Parameters:

102

- name: Redditor username

103

- fullname: Reddit fullname (t2_xxxxx)

104

105

Returns:

106

Redditor instance

107

"""

108

109

def subreddit(self, display_name: str):

110

"""

111

Return a Subreddit instance.

112

113

Parameters:

114

- display_name: Subreddit name (without r/ prefix)

115

116

Returns:

117

Subreddit instance

118

"""

119

```

120

121

### Content Discovery Methods

122

123

Discover random content and check availability.

124

125

```python { .api }

126

def random_subreddit(self, *, nsfw: bool = False):

127

"""

128

Return a random Subreddit.

129

130

Parameters:

131

- nsfw: Include NSFW subreddits

132

133

Returns:

134

Subreddit instance

135

"""

136

137

def info(self, *, fullnames: Iterable[str] | None = None, subreddits: Iterable[Subreddit | str] | None = None, url: str | None = None):

138

"""

139

Fetch info about Reddit objects.

140

141

Parameters:

142

- fullnames: List of Reddit fullnames

143

- subreddits: List of subreddit names or Subreddit objects

144

- url: URL to get info about

145

146

Returns:

147

Generator of Reddit objects

148

"""

149

150

def username_available(self, name: str) -> bool:

151

"""

152

Check if username is available.

153

154

Parameters:

155

- name: Username to check

156

157

Returns:

158

True if available, False otherwise

159

"""

160

```

161

162

### Domain Listings

163

164

Access domain-specific content listings.

165

166

```python { .api }

167

def domain(self, domain: str):

168

"""

169

Return a DomainListing for a domain.

170

171

Parameters:

172

- domain: Domain name (e.g., "reddit.com")

173

174

Returns:

175

DomainListing instance

176

"""

177

```

178

179

### Direct API Requests

180

181

Make direct HTTP requests to Reddit's API.

182

183

```python { .api }

184

def get(self, path: str, *, params: str | dict[str, str | int] | None = None):

185

"""

186

Make GET request to Reddit API.

187

188

Parameters:

189

- path: API endpoint path

190

- params: Query parameters

191

192

Returns:

193

API response data

194

"""

195

196

def post(self, path: str, *, data: dict[str, str | Any] | bytes | IO | str | None = None, files: dict[str, IO] | None = None, json: dict[Any, Any] | list[Any] | None = None, params: str | dict[str, str] | None = None):

197

"""

198

Make POST request to Reddit API.

199

200

Parameters:

201

- path: API endpoint path

202

- data: Form data

203

- files: File uploads

204

- json: JSON data

205

- params: Query parameters

206

207

Returns:

208

API response data

209

"""

210

211

def put(self, path: str, *, data: dict[str, str | Any] | bytes | IO | str | None = None, json: dict[Any, Any] | list[Any] | None = None):

212

"""

213

Make PUT request to Reddit API.

214

215

Parameters:

216

- path: API endpoint path

217

- data: Form data

218

- json: JSON data

219

220

Returns:

221

API response data

222

"""

223

224

def patch(self, path: str, *, data: dict[str, str | Any] | bytes | IO | str | None = None, json: dict[Any, Any] | list[Any] | None = None, params: str | dict[str, str] | None = None):

225

"""

226

Make PATCH request to Reddit API.

227

228

Parameters:

229

- path: API endpoint path

230

- data: Form data

231

- json: JSON data

232

- params: Query parameters

233

234

Returns:

235

API response data

236

"""

237

238

def delete(self, path: str, *, data: dict[str, str | Any] | bytes | IO | str | None = None, json: dict[Any, Any] | list[Any] | None = None, params: str | dict[str, str] | None = None):

239

"""

240

Make DELETE request to Reddit API.

241

242

Parameters:

243

- path: API endpoint path

244

- data: Form data

245

- json: JSON data

246

- params: Query parameters

247

248

Returns:

249

API response data

250

"""

251

252

def request(self, *, method: str, path: str, params: str | dict[str, str | int] | None = None, data: dict[str, str | Any] | bytes | IO | str | None = None, files: dict[str, IO] | None = None, json: dict[Any, Any] | list[Any] | None = None):

253

"""

254

Make generic request to Reddit API.

255

256

Parameters:

257

- method: HTTP method

258

- path: API endpoint path

259

- params: Query parameters

260

- data: Form data

261

- files: File uploads

262

- json: JSON data

263

264

Returns:

265

API response data

266

"""

267

```

268

269

### Client Properties

270

271

Control client behavior and access helper objects.

272

273

```python { .api }

274

@property

275

def read_only(self) -> bool:

276

"""Whether client is in read-only mode."""

277

278

@read_only.setter

279

def read_only(self, value: bool):

280

"""Set read-only mode."""

281

282

@property

283

def validate_on_submit(self) -> bool:

284

"""Whether to validate submissions (deprecated)."""

285

286

@validate_on_submit.setter

287

def validate_on_submit(self, value: bool):

288

"""Set validation on submit (deprecated)."""

289

```

290

291

### Helper Object Access

292

293

Access specialized helper objects for different Reddit functionality areas.

294

295

```python { .api }

296

auth: Auth # Authentication management

297

front: Front # Front page listings

298

inbox: Inbox # User inbox functionality

299

user: User # Current user operations

300

subreddits: Subreddits # Subreddit discovery

301

redditors: Redditors # Redditor discovery

302

drafts: DraftHelper # Draft management

303

live: LiveHelper # Live thread management

304

multireddit: MultiredditHelper # Multireddit management

305

notes: RedditModNotes # Moderator notes

306

```

307

308

## Configuration

309

310

PRAW can be configured through praw.ini files, environment variables, or constructor parameters. The configuration system supports multiple sites and environments.

311

312

**Configuration File (praw.ini):**

313

```ini

314

[DEFAULT]

315

user_agent=MyBot v1.0 by /u/username

316

317

[my_bot]

318

client_id=your_client_id

319

client_secret=your_client_secret

320

username=your_username

321

password=your_password

322

```

323

324

**Environment Variables:**

325

- `praw_client_id`

326

- `praw_client_secret`

327

- `praw_username`

328

- `praw_password`

329

- `praw_user_agent`

330

331

## Types

332

333

```python { .api }

334

class Config:

335

"""PRAW configuration management."""

336

CONFIG_NOT_SET: str # Sentinel for unset config values

337

```