Skip to content

0.3.0 - parsing `request.Response` JSON into Python objects

Compare
Choose a tag to compare
@tjkessler tjkessler released this 08 Jul 04:04
· 91 commits to main since this release
8dae75c

As the title suggests, various functions/classes have been implemented to help users parse Lemmy API responses (requests.Response objects) into easily-usable Python objects. These functions/classes were designed based on how the lemmy-js-client handles responses and data types (person, comment, community, etc.).

For example:

from plemmy import LemmyHttp
from plemmy.responses import GetCommunityResponse

# create object for `Lemmy.ml`, log in
srv = LemmyHttp("https://lemmy.ml")
srv.login("<username_or_email>", "<password>")

# obtain community, parse response
api_response = srv.get_community(name="Lemmy")  # returns `requests.Response` object
response = GetCommunityResponse(api_response)

# print community info
community = response.community_view.community
print(community.name)
print(community.actor_id)
print(community.id)

Full documentation is on its way, in the meantime browse our source code and examples!