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.
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_idstr: Stable identifier of the authenticated user.usernamestr: Username the credentials resolve to.is_platform_adminbool: Whether the user holds platform-wide administrator rights.rolestr:"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
usernamestr: Username.passwordstr: User password.base_urlstr | None: Base URL of theaip-apiservice. Resolved independently of anyaip.init()call you make with the returned token -- falls back toAIP_API_URL, then the config file, thenhttp://localhost:8010if left unset (seeget_config()). Pass it explicitly to target the same host you intend toinit()against.clientAPIClient | None: Optional pre-configuredAPIClient. When provided,base_urlis ignored.
Returns
LoginResult: class:LoginResultcontainingaccess_tokenand identity fields.
Raises
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
clientAPIClient | None: Connection to query. Defaults to the connection established byinit(), or one resolved from the environment wheninit()was never called.
Returns
AuthStatus: class:AuthStatusdescribing 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})")