$ show halcy/Mastodon.py
Mastodon.py is a mature Python client library for the Mastodon social network API. It provides a comprehensive, type-safe interface to all Mastodon endpoints (statuses, accounts, timelines, notifications, admin, streaming, etc.) with built-in pagination, rate limiting, OAuth authentication, and version compatibility detection. The library is split across multiple modules that compose a single `Mastodon` class via inheritance, offering both synchronous and streaming access. It is extensively tested against a local Mastodon instance using VCR-recorded cassettes and supports optional features like WebPush notifications, blurhash decoding, and grapheme-based status length calculation. The codebase is well-maintained with modern Python packaging (pyproject.toml), type annotations, and support for Python 3.6 through 3.14.
The LLM identified 1 files worth highlighting for reuse:
Defines the base classes `AttribAccessDict`, `PaginatableList`, `Entity`, and `EntityList` that form the core of Mastodon.py's return type system. `AttribAccessDict` provides attribute-style access to JSON responses with optional field renaming and backward compatibility maps. `PaginatableList` extends list with pagination info (`_pagination_next`, `_pagination_prev`), enabling seamless cursor-based navigation. The `Entity` and `EntityList` classes add `to_json()`/`from_json()` serialization with version metadata and recursive casting via `try_cast_recurse`, which handles nested types, unions, and special cases like differentiating `Quote` from `ShallowQuote`. This module is self-contained (only imports `compat.py` for forward references) and can be extracted as a generic typed-dict-with-pagination library for any JSON API.