-
Notifications
You must be signed in to change notification settings - Fork 0
The Configuration Files
The Python Reddit API Wrapper comes with a file, reddit/praw.ini which provides the default global variables for reddit sites, as well as defines two sites.
There are three locations that PRAW searches and loads praw.ini files:
The first location, global, is in the praw package location. This file provides the system wide defaults. This file should never be modified.
The second location, user, depends on your operating system. Assuming typical operating system installations and the username foobar the path for specific operating systems should be:
- WINDOWS XP: C:\Documents and Settings\foobar\Application Data\praw.ini
- WINDOWS Vista/7: C:\Users\foobar\AppData\Roaming\praw.ini
- OS with XDG_CONFIG_HOME defined: $XDG_CONFIG_HOME/praw.ini
- OS X / Linux: /home/foobar/.config/praw.ini
The final location, local, is the current working directory. This location works best if you want script-specific configuration files.
Note, that while the settings contained in these file are addative, in cases where the same site and variables are defined in multiple files the local settings take precedence, followed by the user settings, and finally the global settings.
The following variables are provided in the [DEFAULT] section of the global config file. Each site can overwrite any of these variables.
- api_request_delay: A float that defines the number of seconds required between calls to the same domain.
- cache_timeout: An integer that defines the number of seconds to internally cache GET/POST requests based on URL.
- default_content_limit: An integer that defines the default maximum number of results to fetch in a single request for API requests that are potentially unbounded such as get_front_page, get_inbox, and flairlist.
- xxx_kind: A string that maps the type returned by json results to a local object. xxx is one of: comment, message, more, redditor, submission, subreddit, userlist. This mapping is needed as the mappings are created dynamically on site creation and thus isn't consistent across sites.
The are additional variables that each site can define. These additional variables are:
-
domain: (REQUIRED) A string that provides the domain name, and optionally port, used to connect to the desired reddit site. For reddit proper, this is:
www.reddit.com. - ssl_domain: If provided, it is a string similar to domain which is used to make encrypted requests. Currently this is only used for the login method. When not provided, these requests are sent in plaintext (unencrypted).
- user: A string that defines the default username to use when login is called without a user parameter.
- pswd: A string that defines the password to use in conjunction with the provided user.
Please note that while the api_request_delay and cache_timeout can be defined for different sites which point to the same domain, the tracking for each occurs on a per-domain, and not per-site, basis. Essentially, this per-domain tracking means that the time since the last request is the time since the last request from any site to the domain in question. Thus, unexpected event timings may occur if these values differ between sites to the same domain.
The default provided sites are:
- reddit: This site defines the settings for reddit proper. It is also used by default if the site parameter is not defined when creating the Reddit object.
-
local: This site defines settings for a locally running instance of reddit. The xxx_kind mappings may differ so you may need to shadow (overwrite) the 'local' site in your user-level or local-level
praw.inifile.
Additional sites can be added to both represent other installations of reddit on other servers, or to simply provide an additional set of credentials for easy access to that account.
The following is an example praw.ini file which has 4 sites defined. 2 for a reddit proper accounts and 2 for local reddit testing.
[bboe]
domain: www.reddit.com
ssl_domain: ssl.reddit.com
user: bboe
pswd: this_isn't_my_password
[reddit_dev]
domain: www.reddit.com
ssl_domain: ssl.reddit.com
user: someuser
pswd: somepass
[local_dev1]
domain: reddit.local:8000
user: someuser
pswd: somepass
[local_wacky_dev]
domain: reddit.local:8000
user: someuser
pswd: somepass
api_request_delay: 5.0
default_content_limit: 2