mihomo README

The project's README from github.com/MetaCubeX/mihomo. As one markdown file: README.md.

mihomo

A simple python pydantic model (type hint and autocompletion support) for Honkai: Star Rail parsed data from the Mihomo API.

API url: https://api.mihomo.me/sr_info_parsed/{UID}?lang={LANG}

Installation

pip install -U git+https://github.com/KT-Yeh/mihomo.git

Usage

Basic

There are two parsed data formats:

If you don't want to use client.get_icon_url to get the image url everytime, you can use client.fetch_user(800333171, replace_icon_name_with_url=True) to get the parsed data with asset urls.

Example

import asyncio

from mihomo import Language, MihomoAPI
from mihomo.models import StarrailInfoParsed
from mihomo.models.v1 import StarrailInfoParsedV1

client = MihomoAPI(language=Language.EN)


async def v1():
    data: StarrailInfoParsedV1 = await client.fetch_user_v1(800333171)

    print(f"Name: {data.player.name}")
    print(f"Level: {data.player.level}")
    print(f"Signature: {data.player.signature}")
    print(f"Achievements: {data.player_details.achievements}")
    print(f"Characters count: {data.player_details.characters}")
    print(f"Profile picture url: {client.get_icon_url(data.player.icon)}")
    for character in data.characters:
        print("-----------")
        print(f"Name: {character.name}")
        print(f"Rarity: {character.rarity}")
        print(f"Level: {character.level}")
        print(f"Avatar url: {client.get_icon_url(character.icon)}")
        print(f"Preview url: {client.get_icon_url(character.preview)}")
        print(f"Portrait url: {client.get_icon_url(character.portrait)}")


async def v2():
    data: StarrailInfoParsed = await client.fetch_user(800333171, replace_icon_name_with_url=True)

    print(f"Name: {data.player.name}")
    print(f"Level: {data.player.level}")
    print(f"Signature: {data.player.signature}")
    print(f"Profile picture url: {data.player.avatar.icon}")
    for character in data.characters:
        print("-----------")
        print(f"Name: {character.name}")
        print(f"Rarity: {character.rarity}")
        print(f"Portrait url: {character.portrait}")

asyncio.run(v1())
asyncio.run(v2())

Tools

from mihomo import tools

Remove Duplicate Character

    data = await client.fetch_user(800333171)
    data = tools.remove_duplicate_character(data)

Merge Character Data

    old_data = await client.fetch_user(800333171)

    # Change characters in game and wait for the API to refresh
    # ...

    new_data = await client.fetch_user(800333171)
    data = tools.merge_character_data(new_data, old_data)

Data Persistence

Take pickle and json as an example

import pickle
import zlib
from mihomo import MihomoAPI, Language, StarrailInfoParsed

client = MihomoAPI(language=Language.EN)
data = await client.fetch_user(800333171)

# Save
pickle_data = zlib.compress(pickle.dumps(data))
print(len(pickle_data))
json_data = data.json(by_alias=True, ensure_ascii=False)
print(len(json_data))

# Load
data_from_pickle = pickle.loads(zlib.decompress(pickle_data))
data_from_json = StarrailInfoParsed.parse_raw(json_data)
print(type(data_from_pickle))
print(type(data_from_json))

mihomo (MetaCubeX/mihomo)

Searching Database…

34.9K ·GitHub
What is this?It is a Python library built on Pydantic that models and parses the data returned by the Mihomo API for Honkai: Star Rail, giving you typed, autocomplete-friendly access to a player's parsed character and showcase info.
Is this a standalone app or a library I import into my code?It is a pure Python library you import and call directly, not an app or server; you create a client and call methods like fetchuser or fetchuserv1 to get parsed Pydantic model objects.
How do I fetch a player's Honkai: Star Rail data with this?After installing, call client.fetchuser(800333171) for the V2 schema or client.fetchuserv1(800333171) for the older V1 schema, passing the player's in-game UID.
Do I need to fetch asset icon URLs separately myself?No, you can skip that step by calling client.fetchuser(800333171, replaceiconnamewithurl=True), which fills in the asset URLs automatically instead of requiring a separate client.geticonurl call.
What's the difference between the V1 and V2 data formats?V1 and V2 are two separate parsed schemas from the Mihomo API with their own models (StarrailInfoParsedV1 vs StarrailInfoParsed) and fetch methods, defined under separate directories inside mihomo/models.
What utility tools does the library ship with besides fetching data?The mihomo.tools module includes helper functions to remove duplicate characters and to merge character data from multiple fetches.
Can I save fetched player data locally?Yes, the README shows a data persistence example using Python's pickle and json modules to store and reload parsed data.
Creator
MetaCubeX
Size
13.5 MB
Stars
34.9K
Age
5y
Commits · 90 Days