Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# SubredditWidgets

class praw.models.SubredditWidgets(subreddit: praw.models.Subreddit)

  Class to represent a `Subreddit`’s widgets.

  Create an instance like so:

      widgets = reddit.subreddit("test").widgets

  Data will be lazy-loaded. By default, PRAW will not request progressively loading images from Reddit. To enable this, instantiate a `SubredditWidgets` object via `widgets()`, then set the attribute `progressive_images` to `True` before performing any action that would result in a network request.

      widgets = reddit.subreddit("test").widgets
      widgets.progressive_images = True
      for widget in widgets.sidebar:
          # do something
          ...

  Access a `Subreddit`’s widgets with the following attributes:

      print(widgets.id_card)
      print(widgets.moderators_widget)
      print(widgets.sidebar)
      print(widgets.topbar)

  The attribute `id_card` contains the `Subreddit`’s ID card, which displays information like the number of subscribers.

  The attribute `moderators_widget` contains the `Subreddit`’s moderators widget, which lists the moderators of the subreddit.

  The attribute `sidebar` contains a list of widgets which make up the sidebar of the subreddit.

  The attribute `topbar` contains a list of widgets which make up the top bar of the subreddit.

  To edit a `Subreddit`’s widgets, use `mod`. For example:

      widgets.mod.add_text_area(
          short_name="My title",
          text="**bold text**",
          styles={"backgroundColor": "#FFFF66", "headerColor": "#3333EE"},
      )

  For more information, see `SubredditWidgetsModeration`.

  To edit a particular widget, use `.mod` on the widget. For example:

      for widget in widgets.sidebar:
          widget.mod.update(shortName="Exciting new name")

  For more information, see `WidgetModeration`.

  Currently available widgets:

  - `ButtonWidget`

  - `Calendar`

  - `CommunityList`

  - `CustomWidget`

  - `IDCard`

  - `ImageWidget`

  - `Menu`

  - `ModeratorsWidget`

  - `PostFlairWidget`

  - `RulesWidget`

  - `TextArea`

  __init__(subreddit: praw.models.Subreddit)

    Initialize a `SubredditWidgets` instance.

    Parameters:

      subreddit – The `Subreddit` the widgets belong to.

  id_card() → praw.models.IDCard

    Get this `Subreddit`’s `IDCard` widget.

  items() → Dict[str, praw.models.Widget]

    Get this `Subreddit`’s widgets as a dict from ID to widget.

  mod() → praw.models.SubredditWidgetsModeration

    Get an instance of `SubredditWidgetsModeration`.

    Note

    Using any of the methods of `SubredditWidgetsModeration` will likely result in the data of this `SubredditWidgets` being outdated. To re-sync, call `refresh()`.

  moderators_widget() → praw.models.ModeratorsWidget

    Get this `Subreddit`’s `ModeratorsWidget`.

  classmethod parse(data: Dict[str, Any], reddit: praw.Reddit) → Any

    Return an instance of `cls` from `data`.

    Parameters:

      - data – The structured data.

      - reddit – An instance of `Reddit`.

  refresh()

    Refresh the `Subreddit`’s widgets.

    By default, PRAW will not request progressively loading images from Reddit. To enable this, set the attribute `progressive_images` to `True` prior to calling `refresh()`.

        widgets = reddit.subreddit("test").widgets
        widgets.progressive_images = True
        widgets.refresh()

  sidebar() → List[praw.models.Widget]

    Get a list of `Widget`s that make up the sidebar.

  topbar() → List[praw.models.Menu]

    Get a list of `Widget`s that make up the top bar.