### Install Pre-commit Hooks Source: https://praw.readthedocs.io/en/stable/_sources/package_info/contributing.rst.txt Installs pre-commit hooks to automatically enforce code style and PEP compliance on commit. Requires development dependencies to be installed first. ```bash uv run pre-commit install ``` -------------------------------- ### Install PRAW with uv Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/installation.rst.txt Use this command to add PRAW to your project with uv. ```bash uv add praw ``` -------------------------------- ### Install Development Dependencies with uv Source: https://praw.readthedocs.io/en/stable/package_info/contributing.html Installs PRAW in an editable state and development dependencies using uv. This creates a .venv virtual environment. ```bash uv sync ``` -------------------------------- ### Install Development Dependencies Source: https://praw.readthedocs.io/en/stable/_sources/package_info/contributing.rst.txt Installs PRAW and its development dependencies using uv. This creates a virtual environment and installs the 'dev' dependency group. ```bash uv sync ``` -------------------------------- ### Install Latest Development Version from GitHub Repository Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/installation.rst.txt Clone the PRAW repository using git and install the latest development version with pip. ```bash pip install --upgrade git+https://github.com/praw-dev/praw.git ``` -------------------------------- ### Install PRAW with pip Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/installation.rst.txt Use this command to install PRAW using pip. ```bash pip install praw ``` -------------------------------- ### Environment Variable Check Examples Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/configuration/prawini.rst.txt Demonstrates how to check environment variable values in different operating systems and Python. ```bash echo "$" ``` ```bat echo "%%" ``` ```powershell Write-Output "$env:" ``` ```python import os print(os.environ.get("", "")) ``` -------------------------------- ### Install Older PRAW Version with uv Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/installation.rst.txt Specify the version number to install an older version of PRAW using uv. ```bash uv add praw==3.6.0 ``` -------------------------------- ### Install Latest Development Version from GitHub Archive Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/installation.rst.txt Install the latest development version of PRAW directly from a GitHub archive zip file using pip. ```bash pip install --upgrade https://github.com/praw-dev/praw/archive/main.zip ``` -------------------------------- ### Obtain UserSubreddit Instance Source: https://praw.readthedocs.io/en/stable/code_overview/other/usersubreddit.html Demonstrates how to get an instance of the UserSubreddit class. This is the recommended way to initialize it, rather than direct instantiation. ```python subreddit = reddit.user.me().subreddit ``` -------------------------------- ### Creating a New Menu Source: https://praw.readthedocs.io/en/stable/code_overview/other/menu.html Provides an example of how to create a new menu widget with nested items and add it to a subreddit's widgets. ```APIDOC ## Creating a New Menu ### Description This example demonstrates the creation of a new menu widget. It defines the menu structure with text and URLs, including nested children for submenus, and then adds this menu to the subreddit's widgets using `widgets.mod.add_menu()`. ### Method ```python 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()`. ``` -------------------------------- ### Obtain a Subreddit Instance Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/quick_start.rst.txt Shows how to get a Subreddit instance by passing the subreddit's name to the `subreddit` method. ```python subreddit = reddit.subreddit("redditdev") print(subreddit.display_name) # Output: redditdev print(subreddit.title) # Output: reddit development print(subreddit.description) # Output: a subreddit for discussion of ... ``` -------------------------------- ### Get Redditor's Public Multireddits Source: https://praw.readthedocs.io/en/stable/code_overview/models/redditor.html Retrieves a list of public multireddits created by a specific redditor. This example shows how to get multireddits for user 'spez'. ```python multireddits = reddit.redditor("spez").multireddits() ``` -------------------------------- ### WidgetMedia Initialization with File Path Source: https://praw.readthedocs.io/en/stable/code_overview/other/widgetmedia.html Demonstrates initializing WidgetMedia using a file path. The name parameter is optional as it can be inferred from the file path. ```python widget_media = WidgetMedia("/path/to/your/image.png") ``` -------------------------------- ### Get Unread Modmail Count Source: https://praw.readthedocs.io/en/stable/code_overview/other/modmail.html Retrieve the count of unread modmail conversations for a subreddit. This example shows how to access the 'mod' category from the returned dictionary. ```python subreddit = reddit.subreddit("test") unread_counts = subreddit.modmail.unread_count() print(unread_counts["mod"]) ``` -------------------------------- ### Initializing a Media Instance Source: https://praw.readthedocs.io/en/stable/code_overview/other/media.html Use this to initialize a `Media` instance. Provide the file path or content as bytes, and optionally a file name to infer the MIME type. ```python class Media: def __init__(self, fp, name=None): """Initialize a `Media` instance. Parameters: fp (`str` | `bytes`): The path to a media file as a string, or the content of a media file as a `bytes` object. name (`str` | `None`): The name of the media file, e.g., `"picture.png"`. The name is used to infer the media’s MIME type. When `fp` is a path the name is derived from it, otherwise this parameter is required. Return type: None """ pass ``` -------------------------------- ### Get Top Submissions by Redditor Source: https://praw.readthedocs.io/en/stable/code_overview/models/redditor.html Retrieves a ListingGenerator for top items submitted by a redditor, with an option to filter by time. This example outputs the titles of the top 100 submissions of all time for u/spez. ```python for submission in reddit.redditor("spez").submissions.top(time_filter="all"): print(submission.title) ``` -------------------------------- ### WidgetMedia Initialization with Bytes Content Source: https://praw.readthedocs.io/en/stable/code_overview/other/widgetmedia.html Demonstrates initializing WidgetMedia using bytes content. The name parameter is required in this case to infer the media's MIME type. ```python with open("/path/to/your/image.png", "rb") as fp: widget_media = WidgetMedia(fp.read(), name="image.png") ``` -------------------------------- ### Initialize PRAW Config with Keyword Arguments Source: https://praw.readthedocs.io/en/stable/code_overview/other/config.html Demonstrates how to initialize the Config class using keyword arguments for settings. This is useful for programmatic configuration. ```python config = praw.config.Config( site_name="my_reddit_config", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", user_agent="my_reddit_app v1.0.0 by u/YourUsername", username="YOUR_REDDIT_USERNAME", password="YOUR_REDDIT_PASSWORD" ) ``` -------------------------------- ### Initializing PostMedia with Bytes and Name Source: https://praw.readthedocs.io/en/stable/code_overview/other/postmedia.html Initialize a PostMedia instance using raw bytes content and explicitly providing a filename. This is useful when the media content is not stored in a file. ```python with open("picture.png", "rb") as fp: media = praw.models.PostMedia(fp.read(), name="picture.png") ``` -------------------------------- ### Initialize a Listing Instance Source: https://praw.readthedocs.io/en/stable/code_overview/other/listing.html This snippet shows how to initialize a Listing instance. It requires an instance of Reddit and a dictionary containing the data. ```python listing_instance = Listing(reddit, data) ``` -------------------------------- ### GET Request Source: https://praw.readthedocs.io/en/stable/code_overview/reddit_instance.html Return parsed objects returned from a GET request to a specified path. Supports query parameters. ```APIDOC ## get ### Description Return parsed objects returned from a GET request to `path`. ### Method GET ### Endpoint `/{path}` ### Parameters #### Path Parameters - **path** (str) - Required - The path to fetch. #### Query Parameters - **params** (dict[str, str | int] | None) - Optional - The query parameters to add to the request. ### Return Type Any ``` -------------------------------- ### Run Full Test Suite and Checks Source: https://praw.readthedocs.io/en/stable/_sources/package_info/contributing.rst.txt Executes all pre-commit checks, the full test suite, and ensures the documentation builds correctly using tox. Requires development dependencies to be installed. ```bash uv run tox ``` -------------------------------- ### Install Older PRAW Version with pip Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/installation.rst.txt Specify the version number to install an older version of PRAW using pip. ```bash pip install praw==3.6.0 ``` -------------------------------- ### Initializing PostMedia with File Path Source: https://praw.readthedocs.io/en/stable/code_overview/other/postmedia.html Initialize a PostMedia instance using a file path. The 'name' parameter can be omitted if the file path itself contains the filename. ```python media = praw.models.PostMedia("/path/to/your/image.png") ``` -------------------------------- ### Initializing a Reddit Instance Source: https://praw.readthedocs.io/en/stable/code_overview/reddit_instance.html Demonstrates how to initialize a Reddit instance with required authentication credentials and optional settings. ```APIDOC ## Initializing a Reddit Instance ### Description Initialize a `Reddit` instance. This class provides convenient access to Reddit's API. Instances of this class are the gateway to interacting with Reddit's API through PRAW. ### Parameters * **site_name** (`str` | `None`) – The name of a section in your `praw.ini` file from which to load settings from. If `site_name` is `None`, then the site name will be looked for in the environment variable `praw_site`. If it is not found there, the `DEFAULT` site will be used (default: `None`). * **config_interpolation** (`str` | `None`) – Config parser interpolation type that will be passed to `Config` (default: `None`). * **requestor_class** (`type`[`prawcore.requestor.Requestor`] | `None`) – A class that will be used to create a requestor. If not set, use `prawcore.Requestor` (default: `None`). * **requestor_kwargs** (`dict`[`str`, `Any`] | `None`) – Dictionary with additional keyword arguments used to initialize the requestor (default: `None`). * **config_settings** (_str_ _|__bool_ _|__int_ _|__None_) – Additional keyword arguments will be used to initialize the `Config` object. This can be used to specify configuration settings during instantiation of the `Reddit` instance. ### Required Settings * `client_id` * `client_secret` (for installed applications set this value to `None`) * `user_agent` ### Request Example ```python import praw reddit = praw.Reddit( client_id="CLIENT_ID", client_secret="CLIENT_SECRET", password="PASSWORD", user_agent="USERAGENT", username="USERNAME", ) ``` ``` -------------------------------- ### Get the Number of Items in Listing Source: https://praw.readthedocs.io/en/stable/code_overview/other/listing.html Shows how to get the total number of items contained within the Listing. This is useful for iteration or checking if the listing is empty. ```python count = len(listing_instance) ``` -------------------------------- ### Initialize WidgetMedia Source: https://praw.readthedocs.io/en/stable/code_overview/other/widgetmedia.html Initialize a WidgetMedia instance with a file path or bytes content and an optional name. The name is used to infer the media's MIME type. ```python WidgetMedia(fp, name=None) ``` -------------------------------- ### WikiPage.__init__ Source: https://praw.readthedocs.io/en/stable/code_overview/models/wikipage.html Initializes a WikiPage instance, optionally fetching a specific revision. ```APIDOC ## WikiPage.__init__ ### Description Initializes a `WikiPage` instance. By default, it fetches the most recent revision of the wiki page. ### Parameters * **reddit** (_praw.Reddit_) - An instance of the PRAW Reddit API wrapper. * **subreddit** (_models.Subreddit_) - The subreddit the wiki page belongs to. * **name** (_str_) - The name of the wiki page. * **revision** (_str_ | _None_) - A specific revision ID to fetch. If None, the most recent revision is fetched. * **_data** (_dict_[_str_, _Any_] | _None_) - Internal data for the WikiPage object. ``` -------------------------------- ### Get Comment by ID Source: https://praw.readthedocs.io/en/stable/code_overview/reddit_instance.html Retrieves a lazy instance of a Comment object using its ID. Note that to get replies, `refresh()` must be called on the returned Comment object. ```python comment = reddit.comment(id='COMMENT_ID') ``` -------------------------------- ### Python Class Method Signature Example Source: https://praw.readthedocs.io/en/stable/_sources/package_info/contributing.rst.txt Demonstrates PRAW's specific style guideline for methods with multiple arguments, sorting them alphabetically and marking them as keyword-only. ```python class ExampleClass: def example_method( self, *, arg1, arg2, optional_arg1=None, ): ... ``` -------------------------------- ### RulesWidget.__init__() Source: https://praw.readthedocs.io/en/stable/code_overview/other/ruleswidget.html Initializes a new instance of the RulesWidget. ```APIDOC ## RulesWidget.__init__() ### Description Initializes a `RulesWidget` instance. This is typically done internally by PRAW when fetching subreddit widgets. ### Method N/A (Python method) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **reddit** (praw.Reddit) - An instance of the PRAW Reddit API client. - **_data** (dict[str, Any]) - A dictionary containing the raw data for the widget, usually obtained from the Reddit API. ``` -------------------------------- ### Get Subreddit Source: https://praw.readthedocs.io/en/stable/code_overview/other/collection.html Retrieves the Subreddit object to which this collection belongs. ```APIDOC subreddit() ### Description Get the subreddit that this collection belongs to. For example: ```python collection = reddit.subreddit("test").collections("some_uuid") subreddit = collection.subreddit ``` ### Return type `Subreddit` ``` -------------------------------- ### Get the Subreddit of a Collection Source: https://praw.readthedocs.io/en/stable/code_overview/other/collection.html Retrieve the Subreddit object to which the collection belongs. ```python collection = reddit.subreddit("test").collections("some_uuid") subreddit = collection.subreddit ``` -------------------------------- ### Initialize Reddit with Keyword Arguments Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/configuration/reddit_initialization.rst.txt Demonstrates how to initialize a PRAW Reddit instance by explicitly providing keyword arguments for client ID, secret, password, user agent, and username. This method is useful for bypassing the need to configure a specific site in praw.ini. ```python reddit = praw.Reddit( client_id="SI8pN3DSbt0zor", client_secret="xaxkj7HNh8kwg8e5t4m6KvSrbTI", password="1guiwevlfo00esyy", user_agent="testscript by u/fakebot3", username="fakebot3", ) ``` -------------------------------- ### Fetching Live Updates Source: https://praw.readthedocs.io/en/stable/code_overview/models/livethread.html Demonstrates how to initialize a LiveThread object and iterate through its live updates. Use this to continuously fetch new updates from a specific live thread. ```python thread = reddit.live("ukaeu1ik4sw5") after = "LiveUpdate_fefb3dae-7534-11e6-b259-0ef8c7233633" for submission in thread.updates(limit=5, params={"after": after}): print(submission.body) ``` -------------------------------- ### author_notes Source: https://praw.readthedocs.io/en/stable/code_overview/other/commentmoderation.html Get the moderator notes for the author of this object in the subreddit it’s posted in. ```APIDOC ## author_notes ### Description Get the moderator notes for the author of this object in the subreddit it’s posted in. ### Method Not specified (assumed to be a method call on a Comment or Submission object). ### Parameters * **generator_kwargs** (Any) - Additional keyword arguments are passed in the initialization of the moderator note generator. ### Request Example ```python for note in reddit.submission("92dd8").mod.author_notes(): print(f"{note.label}: {note.note}") ``` ### Response #### Success Response A generator of `ModNote`. ``` -------------------------------- ### Get Specific Collection by Permalink Source: https://praw.readthedocs.io/en/stable/code_overview/other/usersubreddit.html Fetches a specific collection from a subreddit using its permalink. ```python collection = reddit.subreddit("test").collections( permalink="https://reddit.com/r/SUBREDDIT/collection/some_uuid" ) ``` -------------------------------- ### ModNote.__init__() Source: https://praw.readthedocs.io/en/stable/code_overview/other/mod_note.html Initializes a ModNote instance. ```APIDOC ## ModNote.__init__() ### Description Initializes a `PRAWBase` instance. ### Parameters - **reddit** (`praw.Reddit`) - An instance of `Reddit`. - **_data** (`dict`[`str`, `Any`] | `None`) - The data for the moderator note. ``` -------------------------------- ### Get Specific Collection by UUID Source: https://praw.readthedocs.io/en/stable/code_overview/other/usersubreddit.html Fetches a specific collection from a subreddit using its UUID. ```python collection = reddit.subreddit("test").collections("some_uuid") ``` -------------------------------- ### Constructing Media Instances for Uploads Source: https://praw.readthedocs.io/en/stable/_sources/package_info/praw8_migration.rst.txt Media instances can be constructed from file paths or bytes content. This replaces the need to write media to disk before uploading. ```python from praw.models import PostMedia media_from_path = PostMedia("/path/to/image.png") media_from_bytes = PostMedia(image_bytes, "image.png") ``` -------------------------------- ### Instantiate LiveThread Source: https://praw.readthedocs.io/en/stable/code_overview/reddit/live.html Use this method to get a lazy instance of LiveThread by providing its ID. ```python livethread = reddit.live("ukaeu1ik4sw5") ``` -------------------------------- ### Get Live Thread Contributors Source: https://praw.readthedocs.io/en/stable/code_overview/other/livecontributorrelationship.html Retrieves a list of all contributors for a given live thread. ```APIDOC ## GET /live/{thread_id}/contributors ### Description Return a `RedditorList` for live threads’ contributors. ### Method GET ### Endpoint /live/{thread_id}/contributors ### Parameters #### Path Parameters - **thread_id** (string) - Required - The ID of the live thread. ### Response #### Success Response (200) - **data** (RedditorList) - A list of Redditor objects representing the contributors. ### Response Example { "data": [ { "id": "t2_1", "name": "example_redditor" } ] } ``` -------------------------------- ### Initialize a Submission Instance Source: https://praw.readthedocs.io/en/stable/code_overview/models/submission.html Initialize a Submission instance by providing either a submission ID or a URL. Both cannot be provided simultaneously. ```python submission = reddit.submission("5or86n") ``` -------------------------------- ### Obtain a Collection Instance by Permalink Source: https://praw.readthedocs.io/en/stable/code_overview/other/collection.html Use this method to get a Collection object when you have its permalink. ```python collection = reddit.subreddit("test").collections( permalink="https://reddit.com/r/test/collection/some_uuid" ) ``` -------------------------------- ### Update PRAW with uv Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/installation.rst.txt Run this command to synchronize and upgrade PRAW using uv. ```bash uv sync --upgrade-package praw ``` -------------------------------- ### Create Submission Instance by ID or URL Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/quick_start.rst.txt Demonstrates creating a Submission instance using either its ID or a URL. ```python # assume you have a praw.Reddit instance bound to variable `reddit` submission = reddit.submission("39zje0") print(submission.title) # Output: reddit will soon only be available ... # or submission = reddit.submission(url="https://www.reddit.com/...") ``` -------------------------------- ### Access Top-Level and All Comments Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/quick_start.rst.txt Illustrates how to get a list of top-level comments and all comments from a submission. ```python # assume you have a praw.Reddit instance bound to variable `reddit` top_level_comments = list(submission.comments) all_comments = submission.comments.list() ``` -------------------------------- ### Get Top Posts Source: https://praw.readthedocs.io/en/stable/code_overview/other/usersubreddit.html Retrieves a ListingGenerator for the top posts in a subreddit, optionally filtered by time. ```APIDOC ## Get Top Posts ### Description Retrieves a ListingGenerator for the top posts in a subreddit, optionally filtered by time. ### Method ```python reddit.subreddit("all").top(time_filter="hour") ``` ### Parameters #### Query Parameters - **time_filter** (str) - Optional - Can be one of: "all", "day", "hour", "month", "week", or "year" (default: "all"). ### Raises - **ValueError** - If `time_filter` is invalid. ### Return Type - `Iterator[Any]` - An iterator yielding top posts. ``` -------------------------------- ### Initializing PRAW with a Specific Site (Python) Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/configuration/prawini.rst.txt Select a specific site configuration from praw.ini when initializing the PRAW Reddit instance. ```python import praw reddit = praw.Reddit("bot2", user_agent="bot2 user agent") ``` -------------------------------- ### Get Top-Level Comments Source: https://praw.readthedocs.io/en/stable/getting_started/quick_start.html Retrieve a list of top-level comments from a submission's comments attribute. ```python top_level_comments = list(submission.comments) all_comments = submission.comments.list() ``` -------------------------------- ### StylesheetAsset Constructor Parameters Source: https://praw.readthedocs.io/en/stable/code_overview/other/stylesheetasset.html The constructor accepts the file path or content of the media and an optional name for the file. When 'fp' is a path, the name is derived from it; otherwise, the 'name' parameter is required. ```python praw.models.StylesheetAsset(fp: str | bytes, name: str | None = None) ``` -------------------------------- ### CommentForest.__init__() Source: https://praw.readthedocs.io/en/stable/code_overview/other/commentforest.html Initializes a CommentForest instance, optionally with a list of comments. ```APIDOC ## CommentForest.__init__() ### Description Initialize a `CommentForest` instance. ### Parameters * **submission** (`Submission`) – An instance of `Submission` that is the parent of the comments. * **comments** (`list`[`Comment` | `MoreComments`] | `None`) – Initialize the forest with a list of comments (default: `None`). ``` -------------------------------- ### Get Redditor Instance by Username Source: https://praw.readthedocs.io/en/stable/getting_started/quick_start.html Obtain a Redditor instance by providing their username to the `redditor()` method. ```python redditor2 = reddit.redditor("bboe") print(redditor2.link_karma) # Output: u/bboe's karma ``` -------------------------------- ### Get Redditor Instance from Submission Source: https://praw.readthedocs.io/en/stable/getting_started/quick_start.html Obtain a Redditor instance from the 'author' attribute of a Submission object. ```python redditor1 = submission.author print(redditor1.name) # Output: name of the redditor ``` -------------------------------- ### Retrieve Submission Replies Source: https://praw.readthedocs.io/en/stable/code_overview/reddit/inbox.html Get a ListingGenerator for replies to your submissions. This is helpful for tracking responses to your posts. ```python for reply in reddit.inbox.submission_replies(): print(reply.author) ``` -------------------------------- ### Get Currently Featured Live Thread Source: https://praw.readthedocs.io/en/stable/code_overview/reddit/live.html Retrieve the currently featured live thread on Reddit. ```APIDOC ## LiveHelper.now() ### Description Get the currently featured live thread. ### Return Type `LiveThread` | `None` ### Returns The `LiveThread` object, or `None` if there is no currently featured live thread. ### Usage ```python thread = reddit.live.now() # LiveThread object or None ``` ``` -------------------------------- ### Get Subreddit Stylesheet Source: https://praw.readthedocs.io/en/stable/code_overview/other/subredditstylesheet.html Retrieve the current stylesheet object for a subreddit. This object can then be modified or inspected. ```python stylesheet = reddit.subreddit("test").stylesheet() ``` -------------------------------- ### Initialize InlineMedia Source: https://praw.readthedocs.io/en/stable/code_overview/other/inlinemedia.html Initializes an InlineMedia instance with optional caption and required media. Use this when creating a self post with embedded media. ```python praw.models.InlineMedia(media=models.PostMedia(...), caption="Optional caption") ``` -------------------------------- ### Get the Number of Posts in a Collection Source: https://praw.readthedocs.io/en/stable/code_overview/other/collection.html Retrieve the total count of posts contained within a collection. ```python collection = reddit.subreddit("test").collections("some_uuid") print(len(collection)) ``` -------------------------------- ### InlineVideo Class Initialization Source: https://praw.readthedocs.io/en/stable/code_overview/other/inlinevideo.html Initializes an InlineVideo instance. Use this to provide a video to embed in text. The media parameter is required, while the caption is optional. ```python class praw.models.InlineVideo(_*, _caption=None, _media) def __init__(_*, _caption=None, _media) ... ``` -------------------------------- ### Get CollectionModeration Instance Source: https://praw.readthedocs.io/en/stable/code_overview/other/collectionmoderation.html Obtain an instance of CollectionModeration to perform moderation actions on a specific collection. ```python reddit.subreddit("test").collections("some_uuid").mod ``` -------------------------------- ### Original URL Search Example Source: https://praw.readthedocs.io/en/stable/_sources/getting_started/faq.rst.txt This is the original code that would be redirected by Reddit when searching for a URL. ```python reddit.subreddit("all").search("https://google.com") ``` -------------------------------- ### Initialize Reddit Instance Source: https://praw.readthedocs.io/en/stable/code_overview/reddit_instance.html This snippet shows the canonical way to obtain an instance of the Reddit class by providing authentication credentials and a user agent. ```python import praw reddit = praw.Reddit( client_id="CLIENT_ID", client_secret="CLIENT_SECRET", password="PASSWORD", user_agent="USERAGENT", username="USERNAME", ) ``` -------------------------------- ### Get Top Posts from Multireddit Source: https://praw.readthedocs.io/en/stable/code_overview/other/usersubreddit.html Retrieve a ListingGenerator for top posts from a multireddit, with options for time filtering. ```Python reddit.multireddit(redditor="samuraisam", name="programming").top(time_filter="day") ``` -------------------------------- ### Instantiate SubredditWidgets Source: https://praw.readthedocs.io/en/stable/code_overview/other/subredditwidgets.html Create an instance of SubredditWidgets to access a subreddit's widgets. ```python widgets = reddit.subreddit("test").widgets ``` -------------------------------- ### Initializing EmojiMedia Source: https://praw.readthedocs.io/en/stable/code_overview/other/emojimedia.html Instantiate EmojiMedia to prepare media for subreddit emoji uploads. Provide the file path or bytes content and optionally a file name to infer the MIME type. ```python EmojiMedia(fp, name=None) ``` -------------------------------- ### Get Top Posts from Subreddit Source: https://praw.readthedocs.io/en/stable/code_overview/other/usersubreddit.html Retrieve a ListingGenerator for top posts from a subreddit, with options for time filtering. ```Python reddit.subreddit("all").top(time_filter="hour") ``` -------------------------------- ### SubredditHelper.create() Source: https://praw.readthedocs.io/en/stable/code_overview/reddit/subreddit.html Creates a new subreddit with the specified name and settings. ```APIDOC ## SubredditHelper.create() ### Description Create a new `Subreddit`. ### Parameters #### Path Parameters - **name** (str) - Required - The name for the new subreddit. - **link_type** (str) - Optional - The types of submissions users can make. One of `"any"`, `"link"`, or `"self"` (default: `"any"`). - **subreddit_type** (str) - Optional - One of `"archived"`, `"employees_only"`, `"gold_only"`, `"gold_restricted"`, `"private"`, `"public"`, or `"restricted"` (default: `"public"`). - **title** (str | None) - Optional - The title of the subreddit. When `None` or `""` use the value of `name`. - **wikimode** (str) - Optional - One of `"anyone"`, `"disabled"`, or `"modonly"` (default: `"disabled"`). - **other_settings** (Any) - Optional - Any keyword parameters not provided, or set explicitly to `None`, will take on a default value assigned by the Reddit server. ### Return Type `Subreddit` ### See Also `update()` for documentation of other available settings. ``` -------------------------------- ### Get Specific Subreddit Rule by Index Source: https://praw.readthedocs.io/en/stable/code_overview/other/subredditrules.html Retrieve a specific rule from a subreddit using its numerical index. ```APIDOC ## Get Specific Subreddit Rule by Index ### Description Return the `Rule` for the subreddit using its numerical index. Rule numbers start at `0`. ### Method GET (Implicit) ### Endpoint subreddit.rules[index] ### Parameters #### Path Parameters - **index** (SupportsIndex) - Required - The numerical index of the rule. Supports negative indexing and slicing. ### Request Example ```python # Get the second rule rule = reddit.subreddit("test").rules[1] # Get the last three rules reasons = reddit.subreddit("test").rules[-3:] for rule in reasons: print(rule) ``` ### Response #### Success Response (200) - **Rule** (Rule) - The requested rule object. #### Error Response - **IndexError** - If a rule with the specified index does not exist. ``` -------------------------------- ### Get Specific Subreddit Rule by Name Source: https://praw.readthedocs.io/en/stable/code_overview/other/subredditrules.html Retrieve a specific rule from a subreddit using its short name. ```APIDOC ## Get Specific Subreddit Rule by Name ### Description Return the `Rule` for the subreddit with short_name `short_name`. ### Method GET (Implicit) ### Endpoint subreddit.rules[short_name] ### Parameters #### Path Parameters - **short_name** (SupportsIndex) - Required - The short_name of the rule. ### Request Example ```python rule_name = "No spam" rule = reddit.subreddit("test").rules[rule_name] print(rule) ``` ### Response #### Success Response (200) - **Rule** (Rule) - The requested rule object. #### Error Response - **IndexError** - If a rule with the specified short_name does not exist. ``` -------------------------------- ### Self Post Inline Media Formatting Example Source: https://praw.readthedocs.io/en/stable/code_overview/models/subreddit.html Illustrates the automatic formatting applied to self-text when including inline media, showing the added padding and markdown for images/videos. ```text Text with a gif ![gif](u1rchuphryq51 "optional caption") an image ![img](srnr8tshryq51 "optional caption") and video ![video](gmc7rvthryq51 "optional caption") inline ``` -------------------------------- ### Create a Live Thread Source: https://praw.readthedocs.io/en/stable/code_overview/reddit_instance.html Create a new live thread with a specified title and description. ```python reddit.live.create(title="title", description="description") ``` -------------------------------- ### Get Unread Conversation Count Source: https://praw.readthedocs.io/en/stable/code_overview/other/modmail.html Returns the count of unread modmail conversations, categorized by conversation state. ```APIDOC ## GET /subreddit/{subreddit_name}/modmail/unread_count ### Description Return unread conversation count by conversation state. ### Method GET ### Endpoint `/subreddit/{subreddit_name}/modmail/unread_count` ### Parameters #### Path Parameters - **subreddit_name** (string) - Required - The name of the subreddit. ### Response #### Success Response (200) - **object** (object) - An object where keys are conversation states and values are the counts of unread conversations for that state. #### Response Example ```json { "new": 5, "mod": 2, "notifications": 10, "appeals": 1 } ``` ``` -------------------------------- ### Create LiveThread Source: https://praw.readthedocs.io/en/stable/code_overview/reddit/live.html Create a new LiveThread with a specified title and optional description, NSFW status, and resources. ```APIDOC ## LiveHelper.create() ### Description Create a new `LiveThread`. ### Parameters #### Path Parameters - **title** (str) - Required - The title of the new `LiveThread`. - **description** (str | None) - Optional - The new `LiveThread`’s description. - **nsfw** (bool) - Optional - Indicate whether this thread is not safe for work (default: `False`). - **resources** (str | None) - Optional - Markdown formatted information that is useful for the `LiveThread`. ### Return Type `LiveThread` ### Returns The new `LiveThread` object. ``` -------------------------------- ### Get Individual Conversation Source: https://praw.readthedocs.io/en/stable/code_overview/other/modmail.html Retrieves a specific modmail conversation by its ID. The conversation can optionally be marked as read. ```APIDOC ## GET /subreddit/{subreddit_name}/modmail/{conversation_id} ### Description Return an individual conversation. ### Method GET ### Endpoint `/subreddit/{subreddit_name}/modmail/{conversation_id}` ### Parameters #### Path Parameters - **subreddit_name** (string) - Required - The name of the subreddit. - **conversation_id** (string) - Required - A reddit base36 conversation ID, e.g., "2gmz". #### Query Parameters - **mark_read** (boolean) - Optional - If True, conversation is marked as read. Defaults to False. ### Response #### Success Response (200) - **ModmailConversation** (object) - A ModmailConversation object. #### Response Example ```json { "id": "conversation_id", "subject": "Subject", "body": "Body", "author": "username", "is_internal": false, "is_spam": false, "messages": [], "user": {}, "replies": [] } ``` ``` -------------------------------- ### ModeratorListing Get Item Source: https://praw.readthedocs.io/en/stable/code_overview/other/moderatorlisting.html Retrieves an item from the moderator list by its index. This method is part of the sequence protocol. ```Python def __getitem__(self, index): return self.items[index] ``` -------------------------------- ### Create a New Collection with Gallery Layout Source: https://praw.readthedocs.io/en/stable/code_overview/other/subredditcollectionsmoderation.html Create a new collection and specify the display layout as 'GALLERY' for images or memes. The authenticated account must have appropriate moderator permissions. ```python my_sub = reddit.subreddit("test") new_collection = my_sub.collections.mod.create( title="Title", description="desc", display_layout="GALLERY" ) new_collection.mod.add_post("bgibu9") ```