Mastodon Single Post Embed via PyScript + Mastodon.py

About This Method

This example uses PyScript to run Python code directly in the browser, with the pyodide_http.patch_all() method to enable the Mastodon.py library.

The Python code in this page fetches the raw status data for post 109349688112355529 from macaw.social using Mastodon.py's status() method (unauthenticated). It then constructs HTML to display the post details and injects it into the page using PyScript's display() function.

This gives full control over rendering using Python, but requires writing the HTML generation code. Be aware that fetching data might fail if the instance requires authentication (even for public posts).

Rendered Post (via PyScript + Mastodon.py)

The following post data was fetched and rendered using Python running in the browser:

Loading post data via PyScript...

Mastodon Embed Examples. Powered by PyScript and Mastodon.py. Styled using Bulma. Find me on Mastodon: @andypiper@macaw.social.

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