Skip to main content

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

Project description

genshin stats api

This project is meant to be a wrapper for the hoyolab.com gameRecord api. I have attempted to reverse engineer their API to find out the important tokens and cookies and then to what urls they are sent. You can pip install with PyPI

how to use

Import the genshin_stats module and do set_cookie(...) to login. You can either use set_cookie(account_id=..., cookie_token=...). The cookie is required and will raise an error if missing. All functions are documented and type hinted.

example

Simple example of usage:

import genshinstats as gs # import module
gs.set_cookie(account_id=8366222, cookie_token="zHbPk8BO3FG4hEOFD2aO6ZlGR1vF75ipuTmFyi2w") # login
result = gs.search('sadru') # search a community user
uid = gs.get_uid_from_community(result['users'][1]['uid']) # get the uid fro the results
user_info = gs.get_user_info(uid) # get user info with the uid
total_characters = len(user_info['avatars']) # get the list of characters, called avatars in the basic API
print('user "sadru" has a total of',total_characters,'characters')

the cookie token in this example is not valid, you must use your own.

prettifiers

There are prettifier functions that turn data into a pretty version. This is to rename some fields that don't make sense, like fetters. These are highly recommended.

characters = gs.prettify_characters(gs.get_all_characters(uid))
for char in characters:
    print(f"{char['rarity']}* {char['name']:10} Level: {char['level']} C{char['constellation']}")

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

about this project

contribution

All contributions are welcome as long as it's in a form of a clean PR.

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.1.1.tar.gz (7.3 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for genshinstats-1.1.1.tar.gz
Algorithm Hash digest
SHA256 c6586331821927a8dfa8e25ac8a2e30052044378620a34e79e24322e6f01b9dd
MD5 d09b268625c72338741ecc76cf4b3e97
BLAKE2b-256 a2045ca7071c35300ebdc5ad15fff5e4d991ca8d9c35310d7a4e301daa10bed7

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