SubredditWidgets¶
- class asyncpraw.models.SubredditWidgets(subreddit: asyncpraw.models.Subreddit)¶
Class to represent a
Subreddit
’s widgets.Create an instance like so:
subreddit = await reddit.subreddit("test") widgets = subreddit.widgets
Data will be lazy-loaded. By default, Async PRAW will not request progressively loading images from Reddit. To enable this, instantiate a
SubredditWidgets
object viawidgets()
, then set the attributeprogressive_images
toTrue
before performing any action that would result in a network request.subreddit = await reddit.subreddit("test") widgets = subreddit.widgets widgets.progressive_images = True async for widget in widgets.sidebar(): # do something ...
Access a
Subreddit
’s widgets with the following attributes:print(await widgets.id_card()) print(await widgets.moderators_widget()) print([widget async for widget in widgets.sidebar()]) print([widget async for widget in widgets.topbar()])
The attribute
id_card
contains theSubreddit
’s ID card, which displays information like the number of subscribers.The attribute
moderators_widget
contains theSubreddit
’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, usemod
. For example:await 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:async for widget in widgets.sidebar(): await widget.mod.update(shortName="Exciting new name")
For more information, see
WidgetModeration
.Currently available widgets:
- __init__(subreddit: asyncpraw.models.Subreddit)¶
Initialize a
SubredditWidgets
instance.- Parameters:
subreddit – The
Subreddit
the widgets belong to.
- await id_card() asyncpraw.models.IDCard ¶
- await items() dict[str, asyncpraw.models.Widget] ¶
Get this
Subreddit
’s widgets as a dict from ID to widget.
- mod() asyncpraw.models.SubredditWidgetsModeration ¶
Get an instance of
SubredditWidgetsModeration
.Note
Using any of the methods of
SubredditWidgetsModeration
will likely result in the data of thisSubredditWidgets
being outdated. To re-sync, callrefresh()
.
- await moderators_widget() asyncpraw.models.ModeratorsWidget ¶
Get this
Subreddit
’sModeratorsWidget
.
- classmethod parse(data: dict[str, Any], reddit: asyncpraw.Reddit) AsyncPRAWBase ¶
Return an instance of
cls
fromdata
.- Parameters:
data – The structured data.
reddit – An instance of
Reddit
.
- await refresh()¶
Refresh the
Subreddit
’s widgets.By default, Async PRAW will not request progressively loading images from Reddit. To enable this, set the attribute
progressive_images
toTrue
prior to callingrefresh()
.subreddit = await reddit.subreddit("test") widgets = subreddit.widgets widgets.progressive_images = True await widgets.refresh()
- async for ... in sidebar() list[asyncpraw.models.Widget] ¶
Get a list of
Widget
s that make up the sidebar.
- async for ... in topbar() list[asyncpraw.models.Menu] ¶
Get a list of
Widget
s that make up the top bar.