Skip to content

Utility Functions

utility

Utilities for genshin.py.

Modules:

  • auth

    Auth utilities.

  • concurrency

    Utilities for concurrency optimizations.

  • deprecation

    Deprecation decorator.

  • ds

    Dynamic secret generation.

  • extdb

    External databases for Genshin Impact data.

  • fs

    File system related utilities.

  • logfile

    Search logfile for authkeys.

  • uid

    Utility functions related to genshin.

Functions:

create_short_lang_code

create_short_lang_code(lang: str) -> str

Create an alternative short lang code.

encrypt_credentials

encrypt_credentials(text: str, key_type: Literal[1, 2]) -> str

Encrypt text for geetest.

extract_authkey

extract_authkey(string: str) -> Optional[str]

Extract an authkey from the provided string.

generate_app_login_ds

generate_app_login_ds(body: dict[str, Any]) -> str

Create a dynamic secret for app login.

generate_cn_dynamic_secret

generate_cn_dynamic_secret(body: Any = None, query: Optional[Mapping[str, Any]] = None, *, salt: str = DS_SALT[CHINESE]) -> str

Create a new chinese dynamic secret.

generate_dynamic_secret

generate_dynamic_secret(salt: str = DS_SALT[OVERSEAS]) -> str

Create a new overseas dynamic secret.

generate_geetest_ds

generate_geetest_ds(region: Region) -> str

Create a dynamic secret for geetest API endpoint.

generate_passport_ds

generate_passport_ds(body: Mapping[str, Any]) -> str

Create a dynamic secret for Miyoushe passport API.

generate_sign

generate_sign(data: dict[str, Any], key: str) -> str

Generate a sign for the given data and app_key.

get_authkey

get_authkey(game_location: Optional[PathLike] = None, *, game: Optional[Game] = None) -> str

Get an authkey contained in a datafile.

get_browser_cookies

get_browser_cookies(browser: Optional[str] = None, *, cookie_file: Optional[str] = None, domains: Sequence[str] = DOMAINS, allowed_cookies: Sequence[str] = ALLOWED_COOKIES) -> Mapping[str, str]

Get hoyolab authentication cookies from your browser for later storing.

Available browsers: chrome, chromium, opera, edge, firefox.

get_ds_headers

get_ds_headers(region: Region, data: Any = None, params: Optional[Mapping[str, Any]] = None, lang: Optional[str] = None) -> dict[str, Any]

Get ds http headers.

get_genshin_banner_ids

get_genshin_banner_ids(logfile: Optional[PathLike] = None) -> Sequence[str]

Get all banner ids from a log file.

get_prod_game_biz

get_prod_game_biz(region: Region, game: Game) -> str

Get the game_biz value corresponding to a game and region.

prevent_concurrency

prevent_concurrency(func: CallableT) -> CallableT

Prevent function from running concurrently.

This should be done exclusively for functions that cache their result.

recognize_game

recognize_game(uid: int, region: Region) -> Optional[Game]

Recognize the game of a uid.

recognize_genshin_server

recognize_genshin_server(uid: int) -> str

Recognize which server a Genshin UID is from.

recognize_honkai_server

recognize_honkai_server(uid: int) -> str

Recognizes which server a Honkai UID is from.

recognize_region

recognize_region(uid: int, game: Game) -> Optional[Region]

Recognize the region of a uid.

recognize_server

recognize_server(uid: int, game: Game) -> str

Recognizes which server a UID is from.

recognize_starrail_server

recognize_starrail_server(uid: int) -> str

Recognize which server a Star Rail UID is from.

recognize_zzz_server

recognize_zzz_server(uid: int) -> str

Recognize which server a Zenless Zone Zero UID is from.

update_characters_ambr async

update_characters_ambr(langs: Sequence[str] = ()) -> None

Update characters with https://ambr.top/.

update_characters_any async

update_characters_any(langs: Union[str, Sequence[str], None] = None, *, lenient: bool = False) -> None

Update characters with the most efficient resource.

Will not re-request data if lenient is True.

update_characters_enka async

update_characters_enka(langs: Sequence[str] = ()) -> None

Update characters with https://github.com/EnkaNetwork/API-docs/.

update_characters_genshindata async

update_characters_genshindata(langs: Sequence[str] = ()) -> None

Update characters with https://github.com/Dimbreath/GenshinData/.

This method requires the download of >20MB per language so it's not recommended.