Fedihosting-Foundation / plemmy

A Python package for accessing the LemmyHttp API
Apache License 2.0
45 stars 15 forks source link

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

Closed tjkessler closed 1 year ago

tjkessler commented 1 year ago

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)