Skip to main content

sasvi.config

Client configuration: base-URL normalization, retry, and HTTP logging.

Defines SVIConfig (the top-level transport configuration), the RetryPolicy and HTTPLogPolicy value objects it composes, and normalize_base_url, which enforces the SDK's URL security defaults (scheme allowlist, userinfo refusal, and plaintext-http guarding). Invalid settings are rejected at construction with ValueError.

verify_ssl_from_env​

def verify_ssl_from_env(
name: str = "SASVI_VERIFY_SSL",
default: bool | str = True,
*,
environ: Mapping[str, str] | None = None) -> bool | str

Read a TLS verification setting from the environment.

Accepts the same boolean words as every other SASVI_* switch, or the path of an existing CA bundle file or certificate directory, which is returned with ~ expanded. Anything else raises, so a typo such as flase or a missing bundle never falls back to some other trust setting.

Arguments:

  • name - Environment variable to read.
  • default - Value returned when the variable is unset.
  • environ - The mapping to read, such as resolved settings; defaults to os.environ.

Returns:

True, False, or the CA bundle path.

Raises:

  • SVIConfigurationError - When the value is neither a boolean word nor the path of an existing file or directory.

normalize_base_url​

def normalize_base_url(base_url: str | None,
*,
allow_insecure: bool = False) -> str | None

Return a usable Viya base URL, defaulting bare hosts to HTTPS.

Schemes are enforced and userinfo is refused:

  • Only https and http schemes are accepted. ftp://, file://, and bare host:port strings (which urlsplit would otherwise read as scheme=host) all raise.
  • http:// is refused for non-loopback hosts unless allow_insecure=True (or the SASVI_ALLOW_INSECURE env var is set). When allowed, a WARNING is emitted via the SDK logger.
  • URLs that carry user-info (https://u:p@host) are refused. Credentials belong on a token provider, not in the URL.

Arguments:

  • base_url - User-supplied base URL or bare host.
  • allow_insecure - Opt-in switch to permit http:// for non-loopback hosts.

RetryPolicy Objects​

@dataclass(frozen=True, slots=True)
class RetryPolicy()

Retry behavior for HTTP calls.

This is the derived, read-only view of the retry settings (SVIConfig's retry_policy property). Configure retries via the flat SVIClient / SVIConfig keyword arguments (max_retries, retry_backoff_seconds, retry_statuses, retry_methods); RetryPolicy is not a constructor argument.

Attributes:

  • max_retries - Maximum retry attempts after the initial request. 0 disables retries entirely.
  • backoff_seconds - Base sleep between retries. Each attempt multiplies by 2**attempt (exponential backoff) with proportional jitter (0.5x-1.5x) to avoid synchronized retry waves; a Retry-After response header is honored when it asks for a longer wait.
  • statuses - HTTP status codes that trigger a retry on retryable methods. Defaults include 408, 429, and 5xx.
  • methods - HTTP methods that may be retried. Defaults to idempotent methods only (GET, HEAD, OPTIONS, PUT, DELETE).
  • request_deadline_seconds - Optional budget for one logical request, covering every attempt and the waits between them. None disables it. Async enforces it as a wall-clock cap. Sync caps each timeout phase at the budget left when an attempt starts and checks the clock between body chunks, so a slow read overshoots by at most one read wait. It is a bound on each wait, not a hard cap.

max_retries​

backoff_seconds​

statuses​

methods​

request_deadline_seconds​

HTTPLogPolicy Objects​

@dataclass(frozen=True, slots=True)
class HTTPLogPolicy()

HTTP request/response logging behavior.

This is the derived, read-only view of the logging settings (SVIConfig's http_log_policy property). Configure logging via the flat SVIClient / SVIConfig log_http* keyword arguments; HTTPLogPolicy is not a constructor argument. All redactable fields (headers, query params, bodies) are sanitized before being emitted; never disable redaction in production.

Attributes:

  • enabled - When True, emit one log record per HTTP request/response.
  • level - Log level for request/response records.
  • request_body - When True, include a truncated, sanitized request body.
  • response_body - When True, include a truncated, sanitized response body.
  • body_limit - Maximum body characters per log record (truncated beyond).
  • query - When True, include sanitized query strings in the URL.
  • headers - When True, include sanitized request and response headers.
  • redacted_headers - Additional case-insensitive header names to redact.
  • redacted_query_params - Additional case-insensitive query names to redact.
  • slow_request_seconds - Threshold above which requests log at WARNING.

enabled​

level​

request_body​

response_body​

body_limit​

query​

headers​

redacted_headers​

redacted_query_params​

slow_request_seconds​

SVIConfig Objects​

@dataclass(frozen=True, slots=True)
class SVIConfig()

Shared runtime configuration for Visual Investigator service clients.

Attributes:

  • base_url - Viya base URL every service path is appended to.
  • service_urls - Absolute per-service URL overrides keyed by service name. Each one goes through normalize_base_url; a path-only value is refused.
  • timeout - Per-request timeout: a scalar applied to every phase, or an httpx2.Timeout for per-phase control. None and a disabled phase are refused.
  • request_deadline_seconds - Wall-clock budget for one logical request across its retries, or None for no cap. Each attempt's timeout phases are capped at the budget left, no retry begins after it is gone, and a per-call timeout= cannot extend it. Async cancels the attempt at the wall clock; sync checks the clock between body chunks, so a slow read overshoots by at most one read wait.
  • max_response_bytes - Largest response body the SDK reads, counted as it arrives, 1 GiB by default. None removes the cap.
  • verify_ssl - TLS verification: True, a CA bundle path, or a shared ssl.SSLContext.
  • follow_redirects - Whether HTTPX follows redirects. Credentials never follow a redirect to another origin.
  • default_headers - Headers sent with every request.
  • user_agent - User-Agent value, applied unless default_headers carries one.
  • raise_on_unexpected_status - Whether generated clients raise on a status the spec does not list.
  • max_retries - Retries after the first attempt for retryable failures.
  • retry_backoff_seconds - Base of the exponential, jittered backoff.
  • retry_statuses - Status codes that are retried on a retryable method.
  • retry_methods - Methods that are retried; writes that are not idempotent are left out.
  • sync_httpx_args - Extra keyword arguments for the sync HTTPX clients.
  • async_httpx_args - Extra keyword arguments for the async HTTPX clients.
  • log_level - SDK package log level applied at client construction, or None to leave logging configuration to the application.
  • log_http - Whether to log one record per HTTP request and response.
  • log_http_level - Level of those records.
  • log_http_request_body - Whether to include a sanitized request body.
  • log_http_response_body - Whether to include a sanitized response body.
  • log_http_body_limit - Characters of body kept per log record.
  • log_http_query - Whether to include sanitized query strings in logged URLs.
  • log_http_headers - Whether to include sanitized headers.
  • log_http_redacted_headers - Extra header names to redact.
  • log_http_redacted_query_params - Extra query parameter names to redact.
  • log_slow_request_seconds - Duration above which a request logs at WARNING.
  • limits - Connection limits for the whole client: one sync pool and one async pool, shared by every service, are each held to it. None uses a limits entry in sync_httpx_args / async_httpx_args for that side, else the HTTPX default (100 connections, 20 kept alive). Setting both this and an HTTPX limits entry is refused. When those arguments carry transport, mounts or proxy, or a proxy is set in the environment, every HTTPX client keeps its own pool and the limit applies to each one.

base_url​

service_urls​

timeout​

request_deadline_seconds​

max_response_bytes​

verify_ssl​

follow_redirects​

default_headers​

user_agent​

raise_on_unexpected_status​

max_retries​

retry_backoff_seconds​

retry_statuses​

retry_methods​

sync_httpx_args​

async_httpx_args​

log_level​

log_http​

log_http_level​

log_http_request_body​

log_http_response_body​

log_http_body_limit​

log_http_query​

log_http_headers​

log_http_redacted_headers​

log_http_redacted_query_params​

log_slow_request_seconds​

limits​

service_url​

def service_url(service_name: str, default_path: str) -> str

Resolve the effective base URL for a generated service.

Arguments:

  • service_name - Logical service name such as "sand" or "alerts".
  • default_path - Default URL path appended to base_url when no override exists.

Returns:

The fully resolved service URL without a trailing slash.

Raises:

  • SVIConfigurationError - If no explicit service override exists and base_url is missing.

headers​

def headers() -> dict[str, str]

Return default headers with a user agent applied when needed.

Returns:

A mutable header dictionary suitable for request construction.

retry_policy​

def retry_policy() -> RetryPolicy

Return the active retry behavior as a RetryPolicy.

Useful for inspection and for passing to other clients that share the same retry profile.

http_log_policy​

def http_log_policy() -> HTTPLogPolicy

Return the active HTTP logging behavior as an HTTPLogPolicy.

http_logging_config​

def http_logging_config() -> HTTPLoggingConfig

Return the normalized internal HTTP logging configuration.

to_dict​

def to_dict() -> PythonObject

Return a JSON-serializable snapshot of the runtime configuration.