PRAW
v6.5.1

Getting Started

  • Quick Start
  • Installing PRAW
  • Authenticating via OAuth
  • Configuring PRAW
  • Running Multiple Instances of PRAW
  • Logging in PRAW

Code Overview

  • The Reddit Instance
  • Working with PRAW’s Models
  • Exceptions in PRAW
  • Other Classes
    • Collection
    • CollectionModeration
    • SubredditCollections
    • SubredditCollectionsModeration
    • SubmissionFlair
    • SubredditFlair
    • SubredditFlairTemplates
    • SubredditLinkFlairTemplates
    • SubredditRedditorFlairTemplates
    • LiveContributorRelationship
    • LiveThreadContribution
    • LiveUpdateContribution
    • CommentModeration
    • SubmissionModeration
    • SubredditModeration
    • SubredditWidgetsModeration
    • ThingModerationMixin
    • WidgetModeration
    • WikiPageModeration
    • ContributorRelationship
    • ModeratorRelationship
    • SubredditRelationship
    • SubredditFilters
    • SubredditQuarantine
    • SubredditStream
    • SubredditModerationStream
    • SubredditStylesheet
    • SubredditWidgets
    • SubredditWiki
    • ButtonWidget
    • Calendar
    • CommunityList
    • CustomWidget
    • IDCard
    • ImageWidget
    • Menu
    • ModeratorsWidget
    • PostFlairWidget
    • RulesWidget
    • TextArea
    • Auth
    • Button
    • CommentForest
    • CommentHelper
    • Config
    • DomainListing
    • Emoji
    • ListingGenerator
    • Image
    • ImageData
    • MenuLink
    • Modmail
    • ModmailMessage
    • Preferences
    • RedditBase
    • RedditorList
    • RemovalReason
    • SubListing
    • Submenu
    • SubredditEmoji
    • SubredditMessage
    • SubredditRemovalReasons
    • RedditorStream
    • Trophy
    • Util

Tutorials

  • Comment Extraction and Parsing
  • Obtaining a Refresh Token
  • Submission Stream Reply Bot

Package Info

  • Change Log
  • Contributing to PRAW
  • References
  • Index
PRAW
  • Docs »
  • Other Classes »
  • Menu
  • Edit on GitHub

Menu¶

class praw.models.Menu(reddit, _data)¶

Class to represent the top menu widget of a subreddit.

Menus can generally be found as the first item in a subreddit’s top bar.

topbar = reddit.subreddit('redditdev').widgets.topbar
if len(topbar) > 0:
    probably_menu = topbar[0]
    assert isinstance(probably_menu, praw.models.Menu)
    for item in probably_menu:
        if isinstance(item, praw.models.Submenu):
            print(item.text)
            for child in item:
                print('\t', child.text, child.url)
        else:  # MenuLink
            print(item.text, item.url)

Create one (requires proper moderator permissions):

widgets = reddit.subreddit('redditdev').widgets
menu_contents = [
    {'text': 'My homepage', 'url': 'https://example.com'},
    {'text': 'Python packages',
     'children': [
         {'text': 'PRAW', 'url': 'https://praw.readthedocs.io/'},
         {'text': 'requests', 'url': 'http://python-requests.org'}
     ]},
    {'text': 'Reddit homepage', 'url': 'https://reddit.com'}
]
menu = widgets.mod.add_menu(menu_contents)

For more information on creation, see add_menu().

Update one (requires proper moderator permissions):

menu_items = list(menu)
menu_items.reverse()
menu = menu.mod.update(data=menu_items)

Delete one (requires proper moderator permissions):

menu.mod.delete()

Typical Attributes

This table describes attributes that typically belong to objects of this class. Since attributes are dynamically provided (see Determine Available Attributes of an Object), there is not a guarantee that these attributes will always be present, nor is this list comprehensive in any way.

Attribute Description
data A list of the MenuLinks and Submenus in this widget. Can be iterated over by iterating over the Menu (e.g. for item in menu).
id The widget ID.
kind The widget kind (always 'menu').
subreddit The Subreddit the button widget belongs to.
__contains__(item: Any) → bool¶

Test if item exists in the list.

__getitem__(index: int) → Any¶

Return the item at position index in the list.

__init__(reddit, _data)¶

Initialize an instance of the class.

__iter__() → Iterator[Any]¶

Return an iterator to the list.

__len__() → int¶

Return the number of items in the list.

mod¶

Get an instance of WidgetModeration for this widget.

Note

Using any of the methods of WidgetModeration will likely make outdated the data in the SubredditWidgets that this widget belongs to. To remedy this, call refresh().

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

Return an instance of cls from data.

Parameters:
  • data – The structured data.
  • reddit – An instance of Reddit.

Note

This list of attributes is not complete. PRAW dynamically provides the attributes that Reddit returns via the API. Because those attributes are subject to change on Reddit’s end, PRAW makes no effort to document them, other than to instruct you on how to discover what is available. See Determine Available Attributes of an Object for detailed information.

Next Previous

© Copyright 2017, Bryce Boe Revision 885edd01.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: v6.5.1
Versions
latest
stable
v6.5.1
v6.5.0
v6.4.0
v6.3.1
v6.3.0
v6.2.0
v6.1.1
v6.1.0
v6.0.0
v5.4.0
v5.3.0
v5.2.0
v5.1.0
v5.0.1
v5.0.0
v4.6.0
v4.5.2
v4.5.1
v4.5.0
v4.4.0
v4.3.0
v4.2.0
v4.1.0
v4.0.0
v3.6.2
v3.6.1
v3.6.0
v3.4.0
v2.1.21
table-fix
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.