$ show MetaCubeX/mihomo
This repository is a Python client library for the Mihomo API, which serves parsed data for the game Honkai: Star Rail. It provides a clean, async client (`MihomoAPI`) that fetches player profiles and character data, mapping the JSON responses into well-structured Pydantic models (version 1 and version 2). The codebase is tightly focused on this single external API, with no data processing or storage beyond the client. Architecture follows a typical API client pattern: a client class with request methods, Pydantic models for data representation, custom error classes, and utility functions for data manipulation (e.g., removing duplicates, merging character records, resolving icon URLs). The library is not a framework or service but a reusable component for any application that needs to consume Honkai: Star Rail player data from the Mihomo API. There are no data pipelines, notebooks, or research elements.
The LLM identified 3 files worth highlighting for reuse:
A module of pure functions for post-processing API response data. Functions like `remove_duplicate_character`, `merge_character_data`, `replace_icon_name_with_url`, and `replace_trailblazer_name` are self-contained, operate on standard dicts or Pydantic models, and can be easily extracted into any project that handles similar data deduplication or URL resolution. They are well-typed and documented, demonstrating solid functional programming style.
Defines a clean exception hierarchy with `BaseException` subclasses for specific failure modes: `HttpRequestError`, `UserNotFound`, `InvalidParams`. Each carries relevant context (status, reason, message). This pattern is directly reusable in any API client project and demonstrates good separation of error concerns without coupling to the rest of the codebase.
An async HTTP client class wrapping the Mihomo API with a single `request` method that handles status codes and raises appropriate custom exceptions. Public methods `fetch_user` and `fetch_user_v1` abstract the two API versions and optionally resolve icon URLs. The client is self-contained, dependency on aiohttp is minimal, and the pattern of a configurable base URL, asset URL, and language enum is reusable for any similar REST API wrapper.