{"id":4172,"library":"praw","title":"Python Reddit API Wrapper (PRAW)","description":"PRAW (Python Reddit API Wrapper) is a Python package that provides a straightforward interface to Reddit's API. It abstracts away much of the complexity, adhering to Reddit's API rules internally, such as managing rate limits. The library is actively maintained, currently at version 7.8.1, with a regular release cadence that often includes new features and bug fixes.","status":"active","version":"7.8.1","language":"en","source_language":"en","source_url":"https://github.com/praw-dev/praw","tags":["reddit","api","wrapper","social media"],"install":[{"cmd":"pip install praw","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Low-level communication layer for PRAW 4+","package":"prawcore","optional":false}],"imports":[{"symbol":"Reddit","correct":"import praw\nreddit = praw.Reddit(...)"}],"quickstart":{"code":"import praw\nimport os\n\n# It's recommended to use a praw.ini file or environment variables for credentials.\n# For quickstart, we'll use environment variables.\n\nreddit = praw.Reddit(\n    client_id=os.environ.get(\"REDDIT_CLIENT_ID\", \"\"),\n    client_secret=os.environ.get(\"REDDIT_CLIENT_SECRET\", \"\"),\n    password=os.environ.get(\"REDDIT_PASSWORD\", \"\"),\n    user_agent=os.environ.get(\"REDDIT_USER_AGENT\", \"my_unique_user_agent_string_v1.0 (by u/YOUR_REDDIT_USERNAME)\"),\n    username=os.environ.get(\"REDDIT_USERNAME\", \"\"),\n)\n\n# Example: Get top 5 hot posts from r/python\nprint(\"Top 5 hot posts from r/python:\")\nfor submission in reddit.subreddit(\"python\").hot(limit=5):\n    print(f\"- {submission.title} (Score: {submission.score})\")\n\n# Example: Access your inbox (requires authenticated instance)\n# try:\n#     for message in reddit.inbox.unread(limit=5):\n#         print(f\"New message: {message.subject}\")\n#         message.mark_read()\n# except prawcore.exceptions.ResponseException as e:\n#     print(f\"Could not access inbox (read_only instance or invalid auth?): {e}\")\n\n# To verify if the instance is read-only:\nprint(f\"Is Reddit instance read-only? {reddit.read_only}\")","lang":"python","description":"This quickstart demonstrates how to initialize PRAW for both read-only (if only client_id, client_secret, and user_agent are provided) or authenticated (if username and password are also provided) access. It then shows how to fetch popular posts from a subreddit. Credentials should ideally be stored in a `praw.ini` file or environment variables, not hardcoded."},"warnings":[{"fix":"Update `except APIException` to `except RedditAPIException as exception:` and iterate through `exception.items` to process individual errors (e.g., `item.error_type`). Direct attribute access like `exception.error_type` on `RedditAPIException` will only work for single errors and is not recommended.","message":"PRAW 7.x introduced significant changes to exception handling. The `APIException` class was renamed to `RedditAPIException` and now acts as a container for multiple `RedditErrorItem` objects, requiring iteration to access individual errors.","severity":"breaking","affected_versions":"7.0.0 and later"},{"fix":"Refactor your code to explicitly use keyword arguments for all function and method calls (e.g., `reddit.subreddit('test').submit(title='Title', selftext='Body')` instead of `reddit.subreddit('test').submit('Title', 'Body')`).","message":"Starting with PRAW 8, most functions and methods will no longer support positional arguments, requiring all arguments to be passed as keyword arguments.","severity":"deprecated","affected_versions":"PRAW 7.x (deprecation warning), PRAW 8.0.0 and later (breaking)"},{"fix":"Use the new `token_manager` keyword argument when initializing `praw.Reddit` with an instance of `BaseTokenManager` (e.g., `FileTokenManager` or `SQLiteTokenManager`) to handle refresh tokens.","message":"The configuration setting `refresh_token` (whether in `praw.ini`, as a keyword argument to `praw.Reddit`, or via `PRAW_REFRESH_TOKEN` environment variable) is deprecated.","severity":"deprecated","affected_versions":"PRAW 7.2.0 and later"},{"fix":"Ensure your `praw.Reddit` instance is properly authenticated with a username and password or a refresh token if you intend to perform actions that modify Reddit. Double-check your `client_id`, `client_secret`, `username`, and `password`. If 2FA is enabled, use a refresh token.","message":"Attempting to perform write actions (e.g., posting, commenting, upvoting) with a read-only `praw.Reddit` instance will result in errors like `prawcore.exceptions.Redirect: Redirect to /r/subreddit/login/` or `invalid_grant`. This often happens when credentials for an authenticated session (username, password, refresh_token) are missing or incorrect.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always provide a descriptive `user_agent` when initializing `praw.Reddit` in the format `<platform>:<app ID>:<version string> (by u/<Reddit username>)`. For example: `user_agent='android:com.example.myredditapp:v1.2.3 (by u/kemitche)'`.","message":"All requests to Reddit's API must include a unique and descriptive User-Agent string. Failure to provide one, or providing a generic one, can lead to your requests being blocked or rate-limited.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}