Skip to content

Base Client

BaseClient

BaseClient(
    cookies: Optional[AnyCookieOrHeader] = None,
    *,
    authkey: Optional[str] = None,
    lang: Lang = "en-us",
    region: Region = OVERSEAS,
    proxy: Optional[str] = None,
    game: Optional[Game] = None,
    uid: Optional[int] = None,
    hoyolab_id: Optional[int] = None,
    device_id: Optional[str] = None,
    device_fp: Optional[str] = None,
    headers: Optional[LooseHeaders] = None,
    cache: Optional[BaseCache] = None,
    debug: bool = False,
    on_cookie_update: Optional[CookieUpdateHook] = None,
)

Base ABC Client.

Methods:

Attributes:

USER_AGENT class-attribute instance-attribute

USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

authkey property writable

authkey: Optional[str]

The default genshin authkey used for paginators.

authkeys instance-attribute

authkeys: dict[Game, str] = {}

cache instance-attribute

cache: BaseCache = cache or StaticCache()

cookie_manager instance-attribute

cookie_manager: BaseCookieManager = from_cookies(cookies)

custom_headers instance-attribute

custom_headers: CIMultiDict[str] = parse_loose_headers(
    headers
)

debug property writable

debug: bool

Whether the debug logs are being shown in stdout

default_game property writable

default_game: Optional[Game]

The default game.

device_fp property writable

device_fp: Optional[str]

The device fingerprint used in headers.

device_id property writable

device_id: Optional[str]

The device id used in headers.

game class-attribute instance-attribute

game = default_game

hoyolab_id property writable

hoyolab_id: Optional[int]

The logged-in user's hoyolab uid.

Returns None if not found or not applicable.

lang property writable

lang: str

The default language, defaults to "en-us"

logger class-attribute instance-attribute

logger: Logger = getLogger(__name__)
on_cookie_update: Optional[CookieUpdateHook]

Callback invoked with a copy of the cookies whenever the client updates them itself.

This happens for example when a new cookie_token is minted from an stoken or when a response sets new cookies. May be a sync or async callable. Use it to persist refreshed cookies so the next client created from storage does not need to refresh again.

proxy property writable

proxy: Optional[str]

Proxy for http requests.

region property writable

region: Region

The default region.

uid property writable

uid: Optional[int]

UID of the default game.

uids instance-attribute

uids: dict[Game, int] = {}

genshin_accounts async

genshin_accounts(
    *, lang: Optional[str] = None
) -> Sequence[GenshinAccount]

Get the genshin accounts of the currently logged-in user.

get_account_timezone

get_account_timezone(
    *,
    game: Optional[Game] = None,
    uid: Optional[int] = None,
) -> Optional[int]

Get the UTC timezone of the default game account.

get_game_accounts async

get_game_accounts(
    *, lang: Optional[str] = None
) -> Sequence[GenshinAccount]

Get the game accounts of the currently logged-in user.

request async

request(
    url: StrOrURL,
    *,
    method: Optional[str] = None,
    params: Optional[Mapping[str, Any]] = None,
    data: Any = None,
    headers: Optional[LooseHeaders] = None,
    cache: Any = None,
    static_cache: Any = None,
    **kwargs: Any,
) -> Mapping[str, Any]

Make a request and return a parsed json response.

request_bbs async

request_bbs(
    url: StrOrURL,
    *,
    lang: Optional[str] = None,
    region: Optional[Region] = None,
    method: Optional[str] = None,
    params: Optional[Mapping[str, Any]] = None,
    data: Any = None,
    headers: Optional[LooseHeaders] = None,
    **kwargs: Any,
) -> Mapping[str, Any]

Make a request any bbs endpoint.

request_hoyolab async

request_hoyolab(
    url: StrOrURL,
    *,
    lang: Optional[str] = None,
    region: Optional[Region] = None,
    method: Optional[str] = None,
    params: Optional[Mapping[str, Any]] = None,
    data: Any = None,
    headers: Optional[LooseHeaders] = None,
    **kwargs: Any,
) -> Mapping[str, Any]

Make a request any hoyolab endpoint.

request_webstatic async

request_webstatic(
    url: StrOrURL,
    *,
    headers: Optional[LooseHeaders] = None,
    cache: Any = None,
    region: Region = OVERSEAS,
    **kwargs: Any,
) -> Any

Request a static json file.

set_authkey

set_authkey(
    authkey: Optional[str] = None,
    *,
    game: Optional[Game] = None,
) -> None

Set an authkey for wish & transaction logs.

Accepts an authkey, a url containing an authkey or a path towards a logfile.

set_browser_cookies

set_browser_cookies(browser: Optional[str] = None) -> None

Extract cookies from your browser and set them as client cookies.

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

set_cache

set_cache(
    maxsize: int = 1024,
    *,
    ttl: int = HOUR,
    static_ttl: int = DAY,
) -> None

Create and set a new cache.

set_cookies

set_cookies(
    cookies: Optional[AnyCookieOrHeader] = None,
    **kwargs: Any,
) -> None

Parse and set cookies.

set_redis_cache

set_redis_cache(
    url: str,
    *,
    ttl: int = HOUR,
    static_ttl: int = DAY,
    **redis_kwargs: Any,
) -> None

Create and set a new redis cache.