Sessions

A Session ties an authorizer to a requestor and exposes the Session.request() method that PRAW uses to communicate with Reddit. The session() helper is the recommended way to construct one.

prawcore.sessions.session(authorizer=None, window_size=600)

Return a Session instance.

Parameters:
Return type:

Session

class prawcore.sessions.Session(authorizer, window_size=600)

The low-level connection interface to Reddit’s API.

Parameters:
property authorizer: BaseAuthorizer

Return the BaseAuthorizer used to authorize requests.

close()

Close the session and perform any clean up.

Return type:

None

property rate_limiter: RateLimiter

Return the RateLimiter that throttles requests.

request(method, path, data=None, files=None, json=None, params=None, timeout=16.0)

Return the json content from the resource at path.

Parameters:
  • method (str) – The request verb. E.g., "GET", "POST", "PUT".

  • path (str) – The path of the request. This path will be combined with the oauth_url of the Requestor.

  • data (dict[str, object] | bytes | IO[Any] | str | None) – Dictionary, bytes, or file-like object to send in the body of the request.

  • files (dict[str, IO[Any]] | None) – Dictionary, mapping filename to file-like object.

  • json (dict[str, object] | list[object] | None) – Object to be serialized to JSON in the body of the request.

  • params (Mapping[str, object] | None) – The query parameters to send with the request.

  • timeout (float) – Specifies a particular timeout, in seconds.

Return type:

dict[str, object] | str | None

Automatically refreshes the access token if it becomes invalid and a refresh token is available.

Raises:

InvalidInvocation in such a case if a refresh token is not available.

Parameters:
Return type:

dict[str, object] | str | None

property requestor: Requestor

Return the Requestor used to issue HTTP requests.