Async PRAW

raw JSON →
7.8.1 verified Mon Apr 27 auth: no python

Async PRAW (asyncpraw) is the asynchronous Python Reddit API Wrapper, allowing for non-blocking interactions with Reddit's API. Current version is 7.8.1, with a release cadence following PRAW's major releases. It requires Python ~=3.8 and supports both OAuth2 and read-only modes.

pip install asyncpraw
error TypeError: object async_generator can't be used in 'await' expression
cause Trying to await an async generator (e.g., `await subreddit.hot()`) instead of iterating over it asynchronously.
fix
Use async for submission in subreddit.hot(limit=10): instead of await subreddit.hot().
error AttributeError: 'Subreddit' object has no attribute 'display_name'
cause A lazy-loaded Subreddit object was used without `fetch=True`, so `display_name` is not populated.
fix
Fetch the subreddit first: subreddit = await reddit.subreddit('learnpython', fetch=True).
error prawcore.exceptions.OAuthException: invalid_grant error processing request
cause OAuth credentials (client_id, client_secret, username, password) are incorrect or not properly set. Common with environment variable typos.
fix
Double-check environment variable names and values. Ensure the Reddit app is a 'script' type. Use os.environ.get('REDDIT_CLIENT_ID', '') and verify the values.
breaking asyncpraw 7.0+ changed the API for many methods to be coroutines. For example, `subreddit.submit()` and `comment.reply()` are now async. Old synchronous calls will fail with TypeError: 'coroutine' object is not subscriptable.
fix Ensure all API calls that return a coroutine are awaited. Use `await subreddit.submit(...)` and `await comment.reply(...)`.
deprecated The `reddit.read_only` attribute to check if the instance is read-only is deprecated in asyncpraw 7.4+. Use `reddit.reader_mode` instead.
fix Replace `reddit.read_only` with `reddit.reader_mode`.
gotcha Explicit `fetch=True` is required when retrieving lazy-loaded objects like Subreddit or Redditor in asyncpraw 7.0+. Otherwise, the object may be empty or raise AttributeError.
fix Always pass `fetch=True` when calling `reddit.subreddit('subname', fetch=True)` or `reddit.redditor('username', fetch=True)`.
gotcha Asyncpraw does not support Python >=3.13 due to asyncio changes. May raise `RuntimeError: Event loop changed` on Windows or Python 3.13+.
fix Use Python 3.8 to 3.12. Monitor asyncpraw GitHub for 3.13 support.

Minimal async example: create a Reddit instance using environment variables for credentials and fetch a subreddit.

import asyncpraw
import os

async def main():
    reddit = asyncpraw.Reddit(
        client_id=os.environ.get('REDDIT_CLIENT_ID', ''),
        client_secret=os.environ.get('REDDIT_CLIENT_SECRET', ''),
        user_agent='asyncpraw:quickstart:v1.0 (by /u/your_username)',
        username=os.environ.get('REDDIT_USERNAME', ''),
        password=os.environ.get('REDDIT_PASSWORD', '')
    )
    subreddit = await reddit.subreddit('learnpython', fetch=True)
    print(f'Subreddit display name: {subreddit.display_name}')

if __name__ == '__main__':
    import asyncio
    asyncio.run(main())