Toggle Menu
Prev Up Next

# `langchain_community.document_loaders.reddit`.RedditPostsLoader

class langchain_community.document_loaders.reddit.RedditPostsLoader(client_id: str, client_secret: str, user_agent: str, search_queries: Sequence[str], mode: str, categories: Sequence[str] = ['new'], number_posts: Optional[int] = 10)

  Load Reddit posts.

  Read posts on a subreddit. First, you need to go to https://www.reddit.com/prefs/apps/ and create your application

  Initialize with client_id, client_secret, user_agent, search_queries, mode,

    categories, number_posts.

  Example: https://www.reddit.com/r/learnpython/

  Parameters

    - client_id (str) – Reddit client id.

    - client_secret (str) – Reddit client secret.

    - user_agent (str) – Reddit user agent.

    - search_queries (Sequence[str]) – The search queries.

    - mode (str) – The mode.

    - categories (Sequence[str]) – The categories. Default: [“new”]

    - number_posts (Optional[int]) – The number of posts. Default: 10

  Methods

  `__init__`(client_id, client_secret, ...[, ...]) | Initialize with client_id, client_secret, user_agent, search_queries, mode,
  `alazy_load`() | A lazy loader for Documents.
  `aload`() | Load data into Document objects.
  `lazy_load`() | A lazy loader for Documents.
  `load`() | Load reddits.
  `load_and_split`([text_splitter]) | Load Documents and split into chunks.

  __init__(client_id: str, client_secret: str, user_agent: str, search_queries: Sequence[str], mode: str, categories: Sequence[str] = ['new'], number_posts: Optional[int] = 10)
    Initialize with client_id, client_secret, user_agent, search_queries, mode,

      categories, number_posts.

    Example: https://www.reddit.com/r/learnpython/

    Parameters

      - client_id (str) – Reddit client id.

      - client_secret (str) – Reddit client secret.

      - user_agent (str) – Reddit user agent.

      - search_queries (Sequence[str]) – The search queries.

      - mode (str) – The mode.

      - categories (Sequence[str]) – The categories. Default: [“new”]

      - number_posts (Optional[int]) – The number of posts. Default: 10

  async alazy_load() → AsyncIterator[Document]

    A lazy loader for Documents.

    Return type

      AsyncIterator[Document]

  async aload() → List[Document]

    Load data into Document objects.

    Return type

      List[Document]

  lazy_load() → Iterator[Document]

    A lazy loader for Documents.

    Return type

      Iterator[Document]

  load() → List[Document]

    Load reddits.

    Return type

      List[Document]

  load_and_split(text_splitter: Optional[TextSplitter] = None) → List[Document]

    Load Documents and split into chunks. Chunks are returned as Documents.

    Do not override this method. It should be considered to be deprecated!

    Parameters

      text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

    Returns

      List of Documents.

    Return type

      List[Document]

# Examples using RedditPostsLoader

- Reddit

- load using ‘subreddit’ mode