py-reddit package

Contents of reddit

class reddit.AsyncClient(agent, key)[source]

Bases: object

Represents an asynchronous Client for fetching reddit posts.

class Subreddit(*args, **kwargs)[source]

Bases: object

Gets the raw data on a subreddit, which can be fetched via the various methods here.

Parameters
  • name (str) – The name of the subreddit

  • mode (str) – ‘top’, ‘hot’, or ‘new’ kind of posts

  • limit (int) – The number of posts to fetch, defaults to 25 if not specified

async author(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

author – The author of a post at the specified index.

Return type

str

async downvotes(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

downvotes – The number of downvotes in a post at the specified index.

Return type

str

async image(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

image – The image url in a post at the specified index.

Return type

str

Raises

KeyError – If the post at the specified index does not have an image.

async num_comments(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

num_comments – The number of comments in a post at the specified index.

Return type

str

Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

permalink – The permalink of a post at the specified index.

Return type

str

async post_url(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

post_url – The url of a post at the specified index.

Return type

str

async raw_json()[source]
Returns

raw_json – The raw json of the response.

Return type

dict

async score(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

score – The score of a post (upvotes-downvotes) at the specified index.

Return type

str

async selftext(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

selftext – The selftext of a post at the specified index.

Return type

str

async title(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

title – The title of a post at the specified index.

Return type

str

async upvotes(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

upvotes – The number of upvotes in a post at the specified index.

Return type

str

class reddit.Client(agent, key)[source]

Bases: object

Represents a synchronous Client for fetching reddit posts.

class Subreddit(mode, name, limit: int = 25)[source]

Bases: object

Gets the raw data on a subreddit, which can be fetched via the various methods here.

Parameters
  • name (str) – The name of the subreddit

  • mode (str) – ‘top’, ‘hot’, or ‘new’ kind of posts

  • limit (int) – The number of posts to fetch, defaults to 25 if not specified

author(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

author – The author of a post at the specified index.

Return type

str

downvotes(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

downvotes – The number of downvotes in a post at the specified index.

Return type

str

image(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

image – The image url in a post at the specified index.

Return type

str

Raises

KeyError – Raised if there’s no image in the post.

num_comments(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

num_comments – The number of comments of a post at the specified index.

Return type

str

Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

permalink – The permalink of a post at the specified index.

Return type

str

post_url(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

post_url – The url of a post at the specified index.

Return type

str

raw_json()[source]
Returns

raw_json – The raw json of the response.

Return type

dict

score(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

score – The score (upvotes-downvotes) of a post at the specified index.

Return type

str

selftext(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

selftext – The selftext of a post at the specified index.

Return type

str

title(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

title – The title of a post at the specified index.

Return type

str

upvotes(index: int)[source]
Parameters

index (int) – The index of the post to fetch (first post is marked as 0)

Returns

upvotes – The number of upvotes in a post at the specified index.

Return type

str