### Installing Plemmy from PyPI (Shell) Source: https://github.com/fedihosting-foundation/plemmy/blob/main/README.md Shows the command to install the Plemmy library from the official Python Package Index (PyPI) using pip. This is the standard and recommended way to install the latest released version. Requires Python with pip installed. ```Shell python -m pip install plemmy ``` -------------------------------- ### Installing Plemmy from Repository (Shell) Source: https://github.com/fedihosting-foundation/plemmy/blob/main/README.md Demonstrates how to install the Plemmy library directly from its GitHub repository using standard shell commands. This method involves cloning the repository and then using `pip install .` within the cloned directory. Requires Git and Python with pip installed. ```Shell git clone https://github.com/Fedihosting-Foundation/plemmy cd plemmy python -m pip install . ``` -------------------------------- ### Initializing LemmyHttp Client and Logging In (Python) Source: https://github.com/fedihosting-foundation/plemmy/blob/main/README.md Illustrates the basic setup for using the Plemmy library. It involves importing the `LemmyHttp` class, creating an instance connected to a specific Lemmy instance URL, and then authenticating a user with a username/email and password using the `login` method. Requires the `plemmy` library installed. Inputs are the Lemmy instance URL, username/email, and password. ```Python from plemmy import LemmyHttp # create object for Lemmy.world, log in srv = LemmyHttp("https://lemmy.world") srv.login("", "") ``` -------------------------------- ### Initializing Plemmy Connection and Logging In (Python) Source: https://github.com/fedihosting-foundation/plemmy/blob/main/examples/search_and_post.ipynb This snippet shows how to establish a connection to a Lemmy instance using `plemmy.LemmyHttp` and then log in with user credentials. It requires the `plemmy` library. The URL, username, and password are required parameters. It returns a `LemmyHttp` service object for subsequent API calls. ```python from plemmy import LemmyHttp # connect to server, log in srv = LemmyHttp("https://lemmy.world") srv.login("", "") ``` -------------------------------- ### Creating and Accessing Lemmy Post Information (Python) Source: https://github.com/fedihosting-foundation/plemmy/blob/main/examples/search_and_post.ipynb This snippet shows how to create a new post in a specified community using the established `srv` object and parse the API response using `plemmy.responses.PostResponse`. It requires the `srv` object and the community ID (obtained from the previous step). The community ID, post title, and body text are required parameters. It outputs details about the newly created post to the console. ```python from plemmy.responses import PostResponse # create a post api_response = srv.create_post(community.id, "Test post please ignore", "Body text") response = PostResponse(api_response) # access post information post = response.post_view.post print(f"Creator ID: {post.creator_id}") print(f"Community ID: {post.community_id}") print(f"Post title: {post.name}") print(f"Post body: {post.body}") ``` -------------------------------- ### Creating and Displaying Post Information (Python) Source: https://github.com/fedihosting-foundation/plemmy/blob/main/README.md Demonstrates the process of creating a new post within a specified community using `srv.create_post()`, parsing the API response with `PostResponse`, and then accessing details of the newly created post such as its creator ID, community ID, title (name), and body text. Requires an authenticated `srv` object and a community ID. Inputs are the community ID, post title, and post body. Output includes printing post properties. ```Python from plemmy.responses import PostResponse # create post, parse JSON api_response = srv.create_post(community.id, "Test post please ignore", "Body text") response = PostResponse(api_response) # post info post = response.post_view.post print(post.creator_id) print(post.community_id) print(post.name) print(post.body) ``` -------------------------------- ### Fetching and Parsing Lemmy Community Information (Python) Source: https://github.com/fedihosting-foundation/plemmy/blob/main/examples/search_and_post.ipynb This snippet demonstrates how to fetch community details from the Lemmy instance using the established `srv` object and parse the API response using `plemmy.responses.GetCommunityResponse`. It requires the `srv` object created by the previous step. The community name is a required parameter. It outputs various details about the community and its moderators to the console. ```python from plemmy.responses import GetCommunityResponse # obtain community, parse JSON api_response = srv.get_community(name="lemmy") response = GetCommunityResponse(api_response) # access community information community = response.community_view.community print(f"Name: {community.name}") print(f"Actor ID: {community.actor_id}") print(f"Num. ID: {community.id}") print(f"Moderators:") for person in response.moderators: print(person.community.name, person.moderator.name, person.moderator.id) ``` -------------------------------- ### Retrieving and Displaying Community Data (Python) Source: https://github.com/fedihosting-foundation/plemmy/blob/main/README.md Shows how to fetch details for a specific community using the `srv.get_community()` method, parse the response using `GetCommunityResponse`, and access various community properties like name, ID, actor ID, and iterate through the list of moderators associated with the community. Requires an authenticated `srv` object. Input is the community name. Output includes printing community properties and moderator names. ```Python from plemmy.responses import GetCommunityResponse # obtain community, parse JSON api_response = srv.get_community(name="Lemmy") response = GetCommunityResponse(api_response) # community info community = response.community_view.community print(community.name) print(community.actor_id) print(community.id) # list community moderators for person in response.moderators: print(person.moderator.name, person.community.name) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.