Skip to content

sift_client.credentials

Credential resolution shared by SiftClient and the pytest plugin.

This module reads the same sift.toml profiles that sift-cli --profile uses. An environment that you configure once for the CLI is then available to the Python client, and you do not restate its endpoints. See :func:resolve_credentials for the precedence order. The Credentials and profiles guide describes the config file.

This module is the public surface. The implementation is in sift_client._internal.credentials.

CLASS DESCRIPTION
ResolvedCredentials

Credentials resolved from arguments, environment, and config file.

FUNCTION DESCRIPTION
resolve_credentials

Resolve Sift credentials across arguments, environment, and sift.toml.

ResolvedCredentials dataclass

ResolvedCredentials(
    api_key: str,
    grpc_url: str,
    rest_url: str,
    app_url: str | None,
    use_ssl: bool,
    profile: str | None,
    sources: Mapping[str, str],
)

Credentials resolved from arguments, environment, and config file.

sources maps each field name to the layer that supplied it: "arg", "profile:<name>", "env", "default", or "unset". Use it to find which environment the client connects to. You then do not have to work through the precedence order by hand.

ATTRIBUTE DESCRIPTION
api_key

TYPE: str

grpc_url

TYPE: str

rest_url

TYPE: str

app_url

TYPE: str | None

use_ssl

TYPE: bool

profile

TYPE: str | None

sources

TYPE: Mapping[str, str]

api_key instance-attribute

api_key: str

grpc_url instance-attribute

grpc_url: str

rest_url instance-attribute

rest_url: str

app_url instance-attribute

app_url: str | None

use_ssl instance-attribute

use_ssl: bool

profile instance-attribute

profile: str | None

sources instance-attribute

sources: Mapping[str, str]

resolve_credentials

resolve_credentials(
    api_key: str | None = None,
    grpc_url: str | None = None,
    rest_url: str | None = None,
    app_url: str | None = None,
    profile: str | None = None,
    config_path: str | None = None,
    env: Mapping[str, str] | None = None,
    require: bool = True,
) -> ResolvedCredentials

Resolve Sift credentials across arguments, environment, and sift.toml.

PARAMETER DESCRIPTION
api_key

Explicit API key, overriding every other layer.

TYPE: str | None DEFAULT: None

grpc_url

Explicit gRPC endpoint, overriding every other layer.

TYPE: str | None DEFAULT: None

rest_url

Explicit REST endpoint, overriding every other layer.

TYPE: str | None DEFAULT: None

app_url

Explicit Sift web-app origin, overriding every other layer.

TYPE: str | None DEFAULT: None

profile

Name of a profile in the config file. It outranks the per-field environment variables. See the module docstring.

TYPE: str | None DEFAULT: None

config_path

Path to a specific config file, bypassing discovery.

TYPE: str | None DEFAULT: None

env

Environment mapping to read, defaulting to os.environ.

TYPE: Mapping[str, str] | None DEFAULT: None

require

If True, raise when the API key or either URL is still missing. Pass False to resolve every field that is available and leave the rest empty. The pytest plugin uses False for its offline mode.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
ResolvedCredentials

The resolved credentials, including which layer supplied each field.

RAISES DESCRIPTION
SiftCredentialsError

This function cannot read or parse the config file, the named profile does not exist, or require is True and a required field is still missing.