redditwarp.client_SYNC#

class redditwarp.client_SYNC.Client[source]#
class redditwarp.client_SYNC.Client(client_id: str, client_secret: str, /)
class redditwarp.client_SYNC.Client(client_id: str, client_secret: str, /, *, grant: AuthorizationGrant)
class redditwarp.client_SYNC.Client(client_id: str, client_secret: str, refresh_token: str, /)
class redditwarp.client_SYNC.Client(client_id: str, client_secret: str, username: str, password: str, /)

Bases: object

Gateway to interacting with the Reddit API.

static from_praw_config(section_name: str, *, filepath: str | None = None) Client[source]#

Initialize a Client instance from a praw.ini file.

This method aims to replicate the single-argument form of PRAW’s Reddit class constructor. If filepath is not specified it will search for praw.ini files in the same locations PRAW does.

Only a subset of PRAW’s configuration keys are read:

  • client_id

  • client_secret

  • refresh_token

  • username

  • password

  • user_agent

The credential values are given directly to the Client constructor, then the user_agent value (if present) is passed to set_user_agent().

Parameters:
  • section_name (str) – The section name of the ini file in which to read values from. Pass an empty string to use the default section name “DEFAULT”.

  • filepath (Optional[str]) –

    The location of a praw.ini file to read.

    If not specified, the locations returned by redditwarp.util.praw_config.get_praw_ini_potential_locations() are searched and any files found are read and combined into a single configuration.

classmethod from_http(http: HTTPClient) _TSelf[source]#

Alternative constructor for testing purposes or advanced use cases.

classmethod from_access_token(access_token: str) _TSelf[source]#

Construct an instance without a token client.

No token client means self.http.authorizer.token_client will be None.

When the access token becomes invalid you’ll need to deal with the 401 Unauthorized StatusCodeException exception that will be thrown upon making API requests.

Use the set_access_token() method to assign new access tokens.

close() None[source]#

Calls self.http.close()

request(verb: str, url: str, *, params: Optional[Mapping[str, str]] = None, headers: Optional[Mapping[str, str]] = None, data: Optional[Union[Mapping[str, str], bytes]] = None, json: JSON_ro = None, files: Optional[RequestFiles] = None, payload: Optional[Payload] = None, timeout: float = -2, follow_redirects: Optional[bool] = None, snub: Optional[Callable[[JSON_ro], None]] = <function raise_for_reddit_error>) Any[source]#

Make an API request and return JSON data.

The parameters are similar to HTTPClient.request, except for snub.

The snub function examines the returned JSON data for API problems and generates exceptions based on them. You may choose to assign this option if you implement an API endpoint and know the structure of the errors, but the default snub function covers most Reddit API error structures.

This method is only appropriate for making calls to the Reddit API and not any other website because of the domain specific post processing that happens with the response data.

Below is a list of the main exception types thrown by this method, ordered by precedence if multiple exceptions apply:

  • redditwarp.exceptions.RedditError

  • redditwarp.http.exceptions.StatusCodeException

  • ValueError

Raises:
set_access_token(access_token: str) None[source]#

Manually set the current access token.

set_user_agent(s: str | None) None[source]#

Set a user agent description.

To view or set the current user agent string directly, use self.http.get_user_agent().

redditwarp.client_SYNC.RedditClient#

alias of Client

redditwarp.client_SYNC.Reddit#

alias of Client

redditwarp.client_SYNC.RedditWarp#

alias of Client