SkillAgentSearch skills...

Genshinstats

PLEASE USE GENSHIN.PY A python library that can get the stats of Genshin Impact players using Mihoyo's API. PLEASE USE GENSHIN.PY

Install / Use

/learn @ashleney/Genshinstats
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

genshinstats

Downloads Downloads/month PyPI package Last Commit Repo Size License Discord

Genshinstats is an unofficial wrapper for the Genshin Impact api. It supports getting user stats, wish history and automatic claiming of daily check-in rewards.

This library only receives bugfixes. Please use genshin.py instead

how to install

using pip

pip install genshinstats

Alternatives:

using pip from git

pip install git+https://github.com/thesadru/genshinstats

clone and install manually

git clone https://github.com/thesadru/genshinstats.git
cd genshinstats
python setup.py install

how to use

You simply need to import the module and use the set_cookie function to login. Since all mihoyo's apis are private there's no kind of api token or authentication header, instead you are required to use your own account cookies. (how can I get my cookies?)

The best way to learn is with examples so I have provided a usage example for every function.

You may also use the documentation

examples

Simple examples of usage:

import genshinstats as gs
gs.set_cookie(ltuid=119480035, ltoken="cnF7TiZqHAAvYqgCBoSPx5EjwezOh1ZHoqSHf7dT")

uid = 710785423
data = gs.get_user_stats(uid)
total_characters = len(data['characters'])
print('user "sadru" has a total of', total_characters, 'characters')

Cookies should be your own. These are just some example cookies of an account that can be deleted at any time.

Note that set_cookie and set_cookies are different functions! The latter should only be used when getting data for other users (for example social media bots)

stats = gs.get_user_stats(uid)['stats']
for field, value in stats.items():
    print(f"{field}: {value}")
# achievements: 210
# active_days: 121
# characters: 19
# ...
characters = gs.get_characters(uid)
for char in characters:
    print(f"{char['rarity']}* {char['name']:10} | lvl {char['level']:2} C{char['constellation']}")
# 5* Xiao       | lvl 90 C0
# 4* Beidou     | lvl 80 C1
# 4* Fischl     | lvl 80 C1
# ...
spiral_abyss = gs.get_spiral_abyss(uid, previous=True)
stats = spiral_abyss['stats']
for field, value in stats.items():
    print(f"{field}: {value}")
# total_battles: 14
# total_wins: 9
# max_floor: 11-3
# total_stars: 19
notes = gs.get_notes(uid)
print(f"Current resin: {notes['resin']}/{notes['max_resin']}")
print(f"Current realm currency: {notes['realm_currency']}/{notes['max_realm_currency']}")
print(f"Expeditions: {len(notes['expeditions'])}/{notes['max_expeditions']}")

It's possible to set the cookies with a header

gs.set_cookie("ltoken=cnF7TiZqHAAvYqgCBoSPx5EjwezOh1ZHoqSHf7dT; ltuid=119480035")

Or set them automatically by getting them from a browser

gs.set_cookie_auto() # search all browsers
gs.set_cookie_auto('chrome') # search specific browser

requires cookie-browser3, can take up to 10s

submodules

wishes

Gets your wish history. For this you must first open the history/details page in genshin impact, you can find the page in the wish menu on the bottom left. The script is then able to get your authkey by itself and fetch the data with it.

for i in gs.get_wish_history():
    print(f"{i['time']} - {i['name']} ({i['rarity']}* {i['type']})")
# 2021-03-22 09:50:12 - Razor (4* Character)
# 2021-03-22 09:50:12 - Harbinger of Dawn (3* Weapon)
# 2021-03-22 09:50:12 - Cool Steel (3* Weapon)
# 2021-03-22 09:50:12 - Emerald Orb (3* Weapon)
# ...
types = gs.get_banner_types() # get all possible types
print(types)
# {100: 'Novice Wishes',
#  200: 'Permanent Wish',
#  301: 'Character Event Wish',
#  302: 'Weapon Event Wish'}

# get pulls only from a specific banner
for i in gs.get_wish_history(301):
    print(f"{i['time']} - {i['name']} ({i['rarity']}* {i['type']})")
banner_ids = gs.get_banner_ids()
for i in banner_ids:
    details = gs.get_banner_details(i) 
    print(f"{details['banner_type_name']} - {details['banner']}")
    print('5 stars:', ', '.join(i['name'] for i in details['r5_up_items']))
    print('4 stars:', ', '.join(i['name'] for i in details['r4_up_items']))
    print()
# Weapon Event Wish - Event Wish "Epitome Invocation"
# 5 stars: Elegy for the End, Skyward Blade
# 4 stars: The Alley Flash, Wine and Song, Favonius Greatsword, Favonius Warbow, Dragon's Bane

get_banner_ids() gets a list of all banners whose details page has been opened in the game.

Basically uses the same approach as get_authkey

View other's history by passing in an authkey:

authkey = "t5QMiyrenV50CFbqnB4Z+aG4ltprY1JxM5YoaChr9QH0Lp6rK5855xxa1P55..."
gs.get_wish_history(size=20, authkey=authkey)

Or by directly setting the authkey:

# directly with the token:
gs.set_authkey("D3ZYe49SUzpDgzrt/l00n2673Zg8N/Yd9OSc7NulRHhp8EhzlEnz2ISBtKBR0fZ/DGs8...")
# get from a url:
gs.set_authkey("https://webstatic-sea.mihoyo.com/ys/event/im-service/index.html?...")
# read from a custom file:
gs.set_authkey('other_output_log.txt')

Since the authkey lasts only a day this is more like for exporting than for actual use.

When importing from platforms like android you must use the authkey manually. (how can I get my authkey?)

daily rewards

Automatically get daily sign in rewards for the currently logged-in user.

reward = gs.claim_daily_reward()
if reward is not None:
    print(f"Claimed daily reward - {reward['cnt']}x {reward['name']}")
else:
    print("Could not claim daily reward")

You can also get a list of all rewards you have claimed so far

for i in gs.get_claimed_rewards():
    print(i['cnt'], i['name'])
# 20 Primogem
# 5000 Mora
# 3 Fine Enhancement Ore
# 3 Adventurer's Experience
# 8000 Mora

transaction logs

Logs for artifact, weapon, resin, genesis crystol and primogem "transactions". You may view a history of everything you have gained in the last 3 months however you may not get the exact amount of any of these so it's generally meant for statistics of gain/loss.

These functions require the same authkey as wish history.

All of these functions work the same:

get_primogem_log
get_resin_log
get_crystal_log
get_artifact_log
get_weapon_log
for i in gs.get_primogem_log(size=40):
    print(f"{i['time']} - {i['reason']}: {i['amount']} primogems")
# 2021-08-14 19:43:12 - Achievement reward: 5 primogems
# 2021-08-13 18:32:58 - Daily Commission reward: 20 primogems
# 2021-08-13 18:22:00 - Daily Commission reward: 10 primogems
# 2021-08-13 18:19:05 - Daily Commission reward: 10 primogems
# 2021-08-13 17:48:09 - Shop purchase: -1600 primogems
total = 0
for i in gs.get_primogem_log():
    total += i['amount']
    print(f"Since {i['time']} you have gained {total} primogems   ", end='\r')
# Since 2021-01-02 20:35:16 you have gained 5197 primogems

Since you the api itself doesn't provide the current amount of resin genshinstats provides a way to calculate it yourself. First it requires a reference to how much primogems you had at a specific time and then it calculates how much you should have currently.

from datetime import datetime

# calculating the current amount of resin based on the fact you had 60 resin on the September 28th 2021 12:00 UTC
print(gs.current_resin(datetime(2021, 9, 28, 12, 00), 60))

Since mihoyo can take up to an hour to update their public database of logs this will only work as long as you haven't used any resin in the last hour

If you do not know how much resin you had at any point you can very roughly approximate it with gs.approximate_current_resin()

hoyolab

Miscalenious stuff for mihoyo's hoyolab. Has searching, auto check-in and code redemption.

# search all users and get their nickname and uid
for user in gs.search('sadru'):
    print(f"{user['nickname']} ({user['uid']}) - \"{user['introduce']}\"")

# check in to hoyolab
gs.hoyolab_check_in()

# get a record card; has user nickname and game uid
card = gs.get_record_card(8366222)
print(f"{card['nickname']} ({card['game_role_id']}) - AR {card['level']}")

# get an in-game uid from a hoyolab uid directly
uid = 8366222
# if it's an actual hoyolab uid
if not gs.is_game_uid(uid): 
    uid = gs.get_uid_from_hoyolab_uid(uid)

You can also redeem gift codes mihoyo gives out during events such as livestreams

gs.redeem_code('GENSHINGIFT')

redeem_code() requires a special form of authentication: an account_id and cookie_token cookies. You can get these by grabbing cookies from the official genshin site instead of hoyolabs.

caching

Caching is currently not native to genshinstats however there's a builtin way to install a cache into every function.

This will cache everything install a cache into every* function in genshinstats.

cache = {}
gs.install_cache(cache)

The same cache reference is used accross all functions allowing you to see the entire cache and possibly even clear it.

cache = {}
gs.install_cache(cache)

gs.get_characters(710785423)
print(cache.keys())
# dict_keys([('get
View on GitHub
GitHub Stars269
CategoryDevelopment
Updated27d ago
Forks37

Languages

Python

Security Score

100/100

Audited on Mar 10, 2026

No findings