> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-codex-docs-audit-20260719-0149.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Reddit

> Query subreddit posts, stats, and trends with RedditTools using praw script-app credentials.

## Prerequisites

1. Create or sign in to a Reddit account at [reddit.com](https://www.reddit.com).
2. Create a script app at [reddit.com/prefs/apps](https://www.reddit.com/prefs/apps).
3. Copy the app's client ID and client secret.

RedditTools can perform read-only operations with the client ID and client secret. Set a username and password only for write operations.

```python theme={null}
from agno.agent import Agent
from agno.tools.reddit import RedditTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    instructions=[
        "Use your tools to answer questions about Reddit content and statistics",
        "Respect Reddit's content policies and NSFW restrictions",
        "When analyzing subreddits, provide relevant statistics and trends",
    ],
    tools=[RedditTools()],
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What are the top 5 posts on r/SAAS this week ?", stream=True)
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai praw
    ```
  </Step>

  <Step title="Export required credentials">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export REDDIT_CLIENT_ID="your_reddit_client_id"
      export REDDIT_CLIENT_SECRET="your_reddit_client_secret"
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:REDDIT_CLIENT_ID="your_reddit_client_id"
      $Env:REDDIT_CLIENT_SECRET="your_reddit_client_secret"
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Set optional Reddit credentials">
    `REDDIT_USER_AGENT` overrides the default user agent. Set `REDDIT_USERNAME` and `REDDIT_PASSWORD` for write operations.

    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export REDDIT_USER_AGENT="platform:app_id:version (by /u/username)"
      export REDDIT_USERNAME="your_reddit_username"
      export REDDIT_PASSWORD="your_reddit_password"
      ```

      ```bash Windows theme={null}
      $Env:REDDIT_USER_AGENT="platform:app_id:version (by /u/username)"
      $Env:REDDIT_USERNAME="your_reddit_username"
      $Env:REDDIT_PASSWORD="your_reddit_password"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `reddit_tools.py`, then run:

    ```bash theme={null}
    python reddit_tools.py
    ```
  </Step>
</Steps>

Full source: [cookbook/91\_tools/reddit\_tools.py](https://github.com/agno-agi/agno/blob/v2.7.4/cookbook/91_tools/reddit_tools.py)
