Skip to main content

aip_sdk.auth

Authentication helpers.

Provides a login() convenience function that exchanges username + password for a JWT bearer token, which can then be passed to init(), and a status() function that reports who the current session is authenticated as.

Use the same API host

login() resolves base_url the same way init() does (env var / config file / default) but independently -- pass it explicitly so it targets the same host you are about to call init() on, rather than whatever that fallback chain happens to resolve to.

Example:

import aip_sdk as aip

result = aip.auth.login("alice", "s3cr3t", base_url="http://localhost:8010")
aip.init("http://localhost:8010", token=result.access_token)

# or in one step:
aip.init("http://localhost:8010", username="alice", password="s3cr3t")

# confirm the session is authenticated
print(aip.auth.status().username)

aip_sdk.auth.AuthStatus​

aip_sdk.auth.AuthStatus(user_id: str, username: str, is_platform_admin: bool, role: str)

Identity behind the credentials the current session is using.

Attributes

  • user_id str: Stable identifier of the authenticated user.
  • username str: Username the credentials resolve to.
  • is_platform_admin bool: Whether the user holds platform-wide administrator rights.
  • role str: "admin" for a platform administrator, otherwise "user".

aip_sdk.auth.AuthStatus.is_platform_admin​

aip_sdk.auth.AuthStatus.is_platform_admin: bool

No docstring is defined in the source.

aip_sdk.auth.AuthStatus.role​

aip_sdk.auth.AuthStatus.role: str

No docstring is defined in the source.

aip_sdk.auth.AuthStatus.user_id​

aip_sdk.auth.AuthStatus.user_id: str

No docstring is defined in the source.

aip_sdk.auth.AuthStatus.username​

aip_sdk.auth.AuthStatus.username: str

No docstring is defined in the source.

aip_sdk.auth.LoginResult​

aip_sdk.auth.LoginResult(access_token: str, token_type: str, user_id: str, username: str, is_platform_admin: bool)

Token and identity returned by a successful login.

aip_sdk.auth.LoginResult.access_token​

aip_sdk.auth.LoginResult.access_token: str

No docstring is defined in the source.

aip_sdk.auth.LoginResult.is_platform_admin​

aip_sdk.auth.LoginResult.is_platform_admin: bool

No docstring is defined in the source.

aip_sdk.auth.LoginResult.token_type​

aip_sdk.auth.LoginResult.token_type: str

No docstring is defined in the source.

aip_sdk.auth.LoginResult.user_id​

aip_sdk.auth.LoginResult.user_id: str

No docstring is defined in the source.

aip_sdk.auth.LoginResult.username​

aip_sdk.auth.LoginResult.username: str

No docstring is defined in the source.

aip_sdk.auth.login​

aip_sdk.auth.login(username: str, password: str, base_url: str | None = None, client: APIClient | None = None) -> LoginResult

Authenticate with username and password, returning a JWT bearer token.

The token is short-lived. Pass LoginResult.access_token to init() as the token argument so subsequent SDK calls are authenticated.

Parameters

  • username str: Username.
  • password str: User password.
  • base_url str | None: Base URL of the aip-api service. Resolved independently of any aip.init() call you make with the returned token -- falls back to AIP_API_URL, then the config file, then http://localhost:8010 if left unset (see get_config()). Pass it explicitly to target the same host you intend to init() against.
  • client APIClient | None: Optional pre-configured APIClient. When provided, base_url is ignored.

Returns

  • LoginResult: class:LoginResult containing access_token and identity fields.

Raises

  • AuthError: If the credentials are invalid (HTTP 401).
  • APIError: On any other HTTP error.

Example:

import aip_sdk as aip

result = aip.auth.login("alice", "s3cr3t", base_url="http://localhost:8010")
aip.init("http://localhost:8010", token=result.access_token)

aip_sdk.auth.status​

aip_sdk.auth.status(client: APIClient | None = None) -> AuthStatus

Report who the current session is authenticated as.

Confirms that the configured credentials are still accepted without creating or modifying anything. Useful before a long-running job, or in a notebook where a short-lived token may have expired since init() ran.

Parameters

  • client APIClient | None: Connection to query. Defaults to the connection established by init(), or one resolved from the environment when init() was never called.

Returns

  • AuthStatus: class:AuthStatus describing the authenticated user.

Raises

  • AuthError: If no credentials are configured, or they are invalid or expired.
  • APIError: On any other HTTP error, or if the response carries no identity.

Example:

import aip_sdk as aip
from aip_sdk import AuthError

aip.init("http://localhost:8010", username="alice", password="s3cr3t")

try:
me = aip.auth.status()
except AuthError:
raise SystemExit("Session is not authenticated.")

print(f"{me.username} (admin: {me.is_platform_admin})")