pythonredditpraw

Is there a way to track API calls through PRAW?


I'm using PRAW in my Python script and am trying to figure out a way to track the number of API calls that it has made. Is there a way to do this?

Regards.


Solution

  • You can enable logging in PRAW : https://praw.readthedocs.io/en/stable/getting_started/logging.html

    From that page:

    When properly configured, HTTP requests that are issued should produce output similar to the following:

    Fetching: GET https://oauth.reddit.com/api/v1/me
    Data: None
    Params: {'raw_json': 1}
    Response: 200 (876 bytes)
    

    Furthermore, any API ratelimits from POST actions that are handled will produce a log entry with a message similar to the following message:

    Rate limit hit, sleeping for 5.5 seconds
    

    Simplest thing you could do is just grep -c over the log looking for Fetching. Or, of course, wire your application to more sophisticated monitoring tools.