Lemmy
Implements the Lemmy class.
Lemmy(lemmy_url, username, password, user_agent, request_timeout=30)
The Lemmy class provides the main entrypoint for pylemmy, and Lemmy's API.
This class manages all the settings relating how to access your chosen Lemmy instance, and implements the Lemmy API.
Example:
from pylemmy import Lemmy
lemmy = Lemmy(
lemmy_url="http://127.0.0.1:8536",
username="lemmy",
password="lemmylemmy",
user_agent="custom user-agent (by u/USERNAME)",
)
Initialize a Lemmy instance.
Parameters:
-
lemmy_url(Union[str, AnyUrl]) –The URL for the Lemmy instance you want to access.
-
username(Optional[str]) –Your Lemmy username or email.
-
password(Optional[str]) –Your Lemmy password
-
user_agent(str) –The user agent the requests will use.
-
request_timeout(int, default:30) –A maximum timeout to wait for requests (in seconds).
Source code in pylemmy/lemmy.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
create_community(name, title, **kwargs)
Create a community with the given name and title.
Parameters:
-
name(str) –Name of the community (stub-like, this will be in the URL).
-
title(str) –Title of the community, in natural language.
-
kwargs–See optional arguments in CreateCommunity.
Source code in pylemmy/lemmy.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
get_comment(comment_id=None)
Get a comment from its id.
Parameters:
-
comment_id(Optional[int], default:None) –Id of the comment.
Source code in pylemmy/lemmy.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
get_community(community)
Get a community by id or name.
Parameters:
-
community(Union[str, int]) –Either a community id (int) or name (str).
Source code in pylemmy/lemmy.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
get_person_details(person_id=None, username=None)
Get a user from its id or username.
Parameters:
-
person_id–Id of the user.
-
username–the username of the user
Source code in pylemmy/lemmy.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
get_post(*, post_id=None, comment_id=None)
Get a post from its id.
Parameters:
-
post_id(Optional[int], default:None) –Id of the post.
-
comment_id(Optional[int], default:None) –Id of the comment.
Source code in pylemmy/lemmy.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
get_request(path, params=None)
Send a GET request to the desired path.
Parameters:
-
path(LemmyAPI) –A Lemmy endpoint.
-
params(Optional[BaseApiModel], default:None) –Parameters to send with the request (in the URL).
Source code in pylemmy/lemmy.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
get_token()
Get the jwt session token.
Source code in pylemmy/lemmy.py
95 96 97 98 99 100 101 | |
get_token_optional()
Get the jwt session token if it exists, or None.
This should be used for requests that don't need authentication.
Source code in pylemmy/lemmy.py
103 104 105 106 107 108 109 110 | |
list_comment_reports(**kwargs)
List comment reports.
Parameters:
-
kwargs–See optional arguments in ListCommentReports.
Source code in pylemmy/lemmy.py
226 227 228 229 230 231 232 233 234 235 236 237 | |
list_communities(**kwargs)
List the communities in the current Lemmy instance.
Parameters:
-
kwargs–See optional arguments in ListCommunities.
Source code in pylemmy/lemmy.py
143 144 145 146 147 148 149 150 151 152 153 | |
list_post_reports(**kwargs)
List post reports.
Parameters:
-
kwargs–See optional arguments in ListPostReports.
Source code in pylemmy/lemmy.py
213 214 215 216 217 218 219 220 221 222 223 224 | |
login()
Login to Lemmy.
If the user is already logged in, return the response to the original login request, with the session information.
Source code in pylemmy/lemmy.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
multi_communities_stream(communities)
Get streams for multiple communities.
Example: A simple example where we want to print the content of each post/comment.
def process_content(elem: Union[Post, Comment]):
if isinstance(Post, elem):
print(elem.post_view.post.name)
elif isinstance(Comment, elem):
print(elem.comment_view.comment.content
multi_stream = lemmy.multi_communities_stream(["community1", "community2"])
multi_stream.content_apply(process_content)
Parameters:
-
communities(Iterable[Union[int, str, Community]]) –An iterable of community ids, names or instances of [Community][pylemmy.community.Community].
Source code in pylemmy/lemmy.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
post_request(path, params=None)
Send a POST request to the desired path.
Parameters:
-
path(LemmyAPI) –A Lemmy endpoint.
-
params(Optional[BaseApiModel], default:None) –Parameters to send with the request (in the body).
Source code in pylemmy/lemmy.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
put_request(path, params=None)
Send a PUT request to the desired path.
Parameters:
-
path(LemmyAPI) –A Lemmy endpoint.
-
params(Optional[BaseApiModel], default:None) –Parameters to send with the request (in the URL).
Source code in pylemmy/lemmy.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |