PRAW
7.6

Getting Started

  • Quick Start
  • Installing PRAW
  • Authenticating via OAuth
  • Configuring PRAW
  • Running Multiple Instances of PRAW
  • Logging in PRAW
  • Ratelimits
  • Frequently Asked Questions

Code Overview

  • The Reddit Instance
  • Working with PRAW’s Models
  • Exceptions in PRAW
  • Other Classes
    • Collection
    • CollectionModeration
    • SubredditCollections
    • SubredditCollectionsModeration
    • SubmissionFlair
    • SubredditFlair
    • SubredditFlairTemplates
    • SubredditLinkFlairTemplates
    • SubredditRedditorFlairTemplates
    • InlineGif
    • InlineImage
    • InlineMedia
    • InlineVideo
    • BaseModNotes
    • ModNote
    • ModNoteMixin
    • RedditModNotes
    • RedditorModNotes
    • SubredditModNotes
    • CommentModeration
    • RuleModeration
    • SubmissionModeration
    • SubredditModeration
    • SubredditRulesModeration
    • SubredditWidgetsModeration
    • ThingModerationMixin
    • UserSubredditModeration
    • WidgetModeration
    • WikiPageModeration
    • LiveContributorRelationship
    • LiveThreadContribution
    • LiveThreadStream
    • LiveUpdateContribution
    • ContributorRelationship
    • ModeratorRelationship
    • SubredditRelationship
    • SubredditEmoji
    • SubredditFilters
    • SubredditModerationStream
    • SubredditQuarantine
    • SubredditRemovalReasons
    • SubredditRules
    • SubredditStream
    • SubredditStylesheet
    • SubredditWidgets
    • SubredditWiki
    • Button
    • ButtonWidget
    • Calendar
    • CalendarConfiguration
    • CommunityList
    • CustomWidget
    • Hover
    • IDCard
    • Image
    • ImageData
    • ImageWidget
    • Menu
    • MenuLink
    • ModeratorsWidget
    • PostFlairWidget
    • RulesWidget
    • Styles
    • Submenu
    • TextArea
    • Widget
    • Auth
    • BaseList
    • CommentForest
    • CommentHelper
    • Config
    • DomainListing
    • DraftList
    • Emoji
    • FullnameMixin
    • InboxableMixin
    • ListingGenerator
    • ModAction
    • ModNote
    • ModeratedList
    • Modmail
    • ModmailMessage
    • PollData
    • PollOption
    • PartialRedditor
    • PRAWBase
    • Preferences
    • RedditBase
    • RedditorList
    • RedditorStream
    • RemovalReason
    • Rule
    • Stylesheet
    • SubListing
    • SubredditMessage
    • Token Manager
    • Trophy
    • UserSubreddit
    • Util

Tutorials

  • Comment Extraction and Parsing
  • Working with Refresh Tokens
  • Submission Stream Reply Bot

Package Info

  • Change Log
  • Contributing to PRAW
  • Glossary
  • Migrating to PRAW 7.X
  • References
  • Sponsors
  • Index
PRAW
  • »
  • Other Classes »
  • Menu
  • View page source

Menu

class praw.models.Menu(reddit: praw.Reddit, _data: Dict[str, Any])

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("test").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:

widgets = reddit.subreddit("test").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(data=menu_contents)

For more information on creation, see add_menu().

Update one:

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

Delete one:

menu.mod.delete()

Typical Attributes

Note

This table describes attributes that typically belong to objects of this class. PRAW dynamically provides the attributes that Reddit returns via the API. Since those attributes are subject to change on Reddit’s end, PRAW makes no effort to document any new/removed/changed attributes, other than to instruct you on how to discover what is available. As a result, this table of attributes may not be complete. See Determine Available Attributes of an Object for detailed information.

If you would like to add an attribute to this table, feel free to open a pull request.

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: praw.Reddit, _data: Dict[str, Any])

Initialize a Widget instance.

__iter__() → Iterator[Any]

Return an iterator to the list.

__len__() → int

Return the number of items in the list.

mod() → praw.models.WidgetModeration

Get an instance of WidgetModeration for this widget.

Note

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

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.

Previous Next

© Copyright 2022, Bryce Boe.

Built with Sphinx using a theme provided by Read the Docs.