scitex_hub.account.whoami

Python parity for scitex-hub account whoami.

Same identity probe the CLI whoami verb hits — GET /api/me/ — so an agent-programmatic caller can confirm “is my cached token still valid?” without shelling out.

Functions

whoami(*[, server, request_fn])

Return the username + email the cached bearer authenticates as.

scitex_hub.account.whoami.whoami(*, server: str | None = None, request_fn=None) dict[source]

Return the username + email the cached bearer authenticates as.

Parameters:
  • server – Override server URL. Defaults to _auth.resolve_server() (env / cache / scitex.ai).

  • request_fn – Dependency-injection seam for the HTTP GET. When None, uses requests.get. Tests inject a fake that returns the same {status_code, json, text} dict shape the real transport produces.

Returns:

Dict with at least username and email (server may add more fields like id or is_staff).

Raises:

RuntimeError – No bearer token resolved (not logged in), token expired (401), or server returned non-200.

Example

>>> from scitex_hub.account.whoami import whoami
>>> whoami()
{'username': 'ywatanabe', 'email': 'ywatanabe@scitex.ai'}
scitex_hub.account.whoami._default_get(url: str, headers: dict) dict[source]

Default GET transport — wraps requests into the dict shape.