packages = ["mastodon-py", "pyodide-http"]

Login Required

To view the timeline, please enter your Mastodon instance URL and log in.

Mastodon User Timeline via PyScript + Mastodon.py

About This Method

This example uses PyScript and the Mastodon.py library (enabled via pyodide_http.patch_all()) to fetch and render a user's timeline directly in the browser after authenticating via OAuth.

The Python code uses an access token stored in the browser's localStorage to authenticate with the Mastodon API. It then fetches the 10 most recent posts for the specified Account ID (109332977621728450 from macaw.social) using api.account_statuses() and renders them below.

Rendered Timeline

Displaying the 10 most recent posts for the configured account:

Loading timeline data via PyScript...