Async PRAW
latest

Getting Started

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

Code Overview

  • The Reddit Instance
  • Working with Async PRAW’s Models
  • Exceptions in Async 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
      • Menu
        • Menu.__contains__()
        • Menu.__getitem__()
        • Menu.__init__()
        • Menu.__iter__()
        • Menu.__len__()
        • Menu.mod()
        • Menu.parse()
    • MenuLink
    • ModeratorsWidget
    • PostFlairWidget
    • RulesWidget
    • Styles
    • Submenu
    • TextArea
    • Widget
    • AsyncPRAWBase
    • Auth
    • BaseList
    • CommentForest
    • CommentHelper
    • Config
    • DomainListing
    • DraftList
    • Emoji
    • FullnameMixin
    • InboxableMixin
    • ListingGenerator
    • ModAction
    • ModNote
    • ModeratedList
    • Modmail
    • ModmailMessage
    • PollData
    • PollOption
    • PartialRedditor
    • 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 Async PRAW
  • Glossary
  • Migrating to Async PRAW
  • Migrating to PRAW 7.X
  • References
  • Index
Async PRAW
  • »
  • Other Classes »
  • Menu
  • Edit on GitHub

Menu¶

class asyncpraw.models.Menu(reddit: asyncpraw.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.

subreddit = await reddit.subreddit("test")
topbar = [widget async for widget in subreddit.widgets.topbar()]
if len(topbar) > 0:
    probably_menu = topbar[0]
    assert isinstance(probably_menu, asyncpraw.models.Menu)
    for item in probably_menu:
        if isinstance(item, asyncpraw.models.Submenu):
            print(item.text)
            for child in item:
                print("\t", child.text, child.url)
        else:  # MenuLink
            print(item.text, item.url)

Create one:

subreddit = await reddit.subreddit("test")
widgets = subreddit.widgets
menu_contents = [
    {"text": "My homepage", "url": "https://example.com"},
    {
        "text": "Python packages",
        "children": [
            {"text": "asyncpraw", "url": "https://asyncpraw.readthedocs.io/"},
            {"text": "requests", "url": "http://python-requests.org"},
        ],
    },
    {"text": "Reddit homepage", "url": "https://reddit.com"},
]
menu = await 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 = await menu.mod.update(data=menu_items)

Delete one:

await menu.mod.delete()

Typical Attributes

Note

This table describes attributes that typically belong to objects of this class. Async PRAW dynamically provides the attributes that Reddit returns via the API. Since those attributes are subject to change on Reddit’s end, Async 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: asyncpraw.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() → asyncpraw.models.WidgetModeration¶

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: asyncpraw.Reddit) → Any¶

Return an instance of cls from data.

Parameters:
  • data – The structured data.

  • reddit – An instance of Reddit.

Next Previous

© Copyright 2023, Joel Payne. Revision 41f6ba7f.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions
latest
stable
v7.6.1
v7.6.0
v7.5.0
v7.4.0
v7.3.1
v7.3.0
v7.2.0
v7.1.1
v7.1.0
upgrade_tests
Downloads
html
On Read the Docs
Project Home
Builds