Skip to main content

A wrapper for the official hoyolab.com Genshin impact gameRecord API.

Project description

genshinstats

This project is meant to be a wrapper for the Genshin Impact's hoyolab.com api. The api endpoints used in this project are not publicly known but are free to use for 3rd part tools, so I have decided to get these a bit more publicity by making a wrapper for them.

You can pip install with PyPI

how to use

Import the genshinstats module and set the cookie to login. To set the cookie use set_cookie(account_id=..., cookie_token=...). Pass your own cookie values in this fields. (How to get your cookie) The cookie is required and will raise an error if missing.

All functions are documented and type hinted.

examples

Simple examples of usage:

import genshinstats as gs # import module
gs.set_cookie(account_id=119480035, cookie_token="hEIIh08ghAIlHY1QQZBnsngVWXzaEMQtrSV0Bowu") # login

uid = 710785423
user_info = gs.get_user_info(uid) # get user info with a uid
total_characters = len(user_info['characters']) # get the amount of 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.

stats = gs.get_user_info(uid)['stats']
for field,value in stats.items():
    print(f"{field.replace('_',' ')}: {value}")
characters = gs.get_all_characters(uid)
for char in characters:
    print(f"{char['rarity']}* {char['name']:10} | lvl {char['level']:2} C{char['constellation']}")
spiral_abyss = gs.get_spiral_abyss(uid,previous=True)
stats = spiral_abyss['stats']
for field,value in stats.items():
    print(f"{field.replace('_',' ')}: {value}")
for player in gs.get_public_players():
    print(f"{player['uid']},{player['community_uid']}\n")

submodules

gachalog

Gets your gacha pull logs. For this you must first open the history/details page in genshin impact, the script will then get all required data by itself.

types = gs.get_gacha_types() # get all possible types
key = types[2]['key'] # name == "Character Event Wish", key == '301'
log = gs.get_gacha_log(key) # get the gacha log
for i in log:
    print(f"{i['time']} - {i['name']} ({i['rarity']}* {i['type']})")
ids = gs.get_all_gacha_ids() # get all possible gacha ids (only counts opened details pages)
for i in ids:
    details = gs.get_gacha_details(i) # 
    print(f"{details['gacha_type']} - {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()

View other's history by setting an authkey yourself:

# 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(logfile='other_output_log.txt')

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

signin

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

info = gs.get_daiy_reward_info()
print('total rewards claimed:',info['total_sign_day'])
gs.sign_in() # signed you in, returns a bool whether it succeeded

change language

Some api endpoints support changing languages, you can see them listed here:

genshinstats.get_all_characters(...,lang='fr-fr')

gachalog.get_gacha_log(...,lang='fr')
gachalog.get_gacha_types(lang='fr')
gachalog.get_gacha_details(...,lang='fr-fr')
gachalog.recognize_gacha_type(lang='fr')

how to get your cookie

  1. go to hoyolab.com
  2. login to your account
  3. open inspect mode (Developer Tools)
  4. go to Application, Cookies, https://www.hoyolab.com.
  5. copy account_id and cookie_token
  6. use set_cookie(account_id=..., cookie_token=...) in your code

errors

genshinstats uses its own errors defined in genshinstats.errors.

The most common one you'll probably see is DataNotPublic. To solve this error You must go to hoyolab.com and make your account public. (how to make your account public)

project layout

genshinstats.py    user stats and characters
hoyolab.py         user hoyolab community info
gachalog.py        gacha history
errors.py          errors used by genshinstats

about this project

contribution

All contributions are welcome as long as it's in a form of a clean PR. Currently looking for people to help me get the ds salt of the new api version.

crediting

This project can be freely downloaded and distributed. Crediting is appreciated.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genshinstats-1.2.9.tar.gz (14.8 kB view details)

Uploaded Source

File details

Details for the file genshinstats-1.2.9.tar.gz.

File metadata

  • Download URL: genshinstats-1.2.9.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0

File hashes

Hashes for genshinstats-1.2.9.tar.gz
Algorithm Hash digest
SHA256 a51434ab4523b33d567d0de7f1b463c5f272affce6948314d37544b7a5b3a846
MD5 800e4637c65f9a04a5047108dabe6334
BLAKE2b-256 ee7fb95a0e9fc73163cb477126550718235cf0391439ba9e54ef5b720d2105b5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page