Skip to main content

sasvi.handles

Public handle base class for raw-payload wrappers.

Every result object that wraps a generated openapi model extends RawBackedHandle. That covers Document, Alert, WorkspaceHandle, InsightHandle and the rest. The base class provides:

  • a stable .raw accessor for the underlying generated model or mapping
  • .raw_dict() to deep-convert the payload into plain Python data (useful for logging or round-tripping through json.dumps)

Most users never construct handles directly; they receive them from a service method like client.documents.get(...) or client.search.run().items.

unset_to_none​

def unset_to_none(value: T | Any) -> T | None

Return None when value is an openapi-generated Unset sentinel.

Used by handwritten result wrappers (Vertex, Edge, CommentRecord, …) to translate the generated X | Unset field types into the cleaner X | None shape that Pylance/Pyright narrow correctly and that reads naturally in user code.

Arguments:

  • value - Any value, possibly an Unset sentinel from the generated openapi models.

Returns:

None if value is an Unset sentinel, otherwise value unchanged.

raw_get​

@overload
def raw_get(raw: object, *names: str) -> object | None

Overload: return None when no name resolves and no default is given.

raw_get​

@overload
def raw_get(raw: object, *names: str, default: DefaultT) -> object | DefaultT

Overload: return the typed default when no name resolves.

raw_get​

def raw_get(raw: object,
*names: str,
default: DefaultT | None = None) -> object | DefaultT | None

Read the first non-UNSET value from a raw model or mapping.

Arguments:

  • raw - Generated model or mapping to inspect.
  • *names - Candidate attribute or key names to try in order.
  • default - Fallback value returned when none of the names resolve.

Returns:

The first resolved non-Unset value, or default.

raw_str​

@overload
def raw_str(raw: object, *names: str) -> str | None

Overload: return None when no name resolves to a str.

raw_str​

@overload
def raw_str(raw: object, *names: str, default: DefaultT) -> str | DefaultT

Overload: return the typed default when no name resolves to a str.

raw_str​

def raw_str(raw: object,
*names: str,
default: DefaultT | None = None) -> str | DefaultT | None

Read the first name that resolves to a str from a raw model or mapping.

Delegates to raw_get, then applies a runtime isinstance check. Mirrors raw_get's lenient contract: a resolved value of the wrong type is treated as absent rather than raising.

Arguments:

  • raw - Generated model or mapping to inspect.
  • *names - Candidate attribute or key names to try in order.
  • default - Fallback returned when no name resolves to a str.

Returns:

The first resolved str value, or default.

raw_int​

@overload
def raw_int(raw: object, *names: str) -> int | None

Overload: return None when no name resolves to an int.

raw_int​

@overload
def raw_int(raw: object, *names: str, default: DefaultT) -> int | DefaultT

Overload: return the typed default when no name resolves to an int.

raw_int​

def raw_int(raw: object,
*names: str,
default: DefaultT | None = None) -> int | DefaultT | None

Read the first name that resolves to an int from a raw model or mapping.

Delegates to raw_get, then applies a runtime isinstance check. A bool is not accepted as an int: although bool is a subclass of int in Python, callers asking for an integer never want True/ False, so a resolved bool is treated as a type mismatch and yields default. Mirrors raw_get's lenient contract, so a wrong-typed value is treated as absent rather than raising.

Arguments:

  • raw - Generated model or mapping to inspect.
  • *names - Candidate attribute or key names to try in order.
  • default - Fallback returned when no name resolves to a non-bool int.

Returns:

The first resolved int value (excluding bool), or default.

raw_float​

@overload
def raw_float(raw: object, *names: str) -> float | None

Overload: return None when no name resolves to a float.

raw_float​

@overload
def raw_float(raw: object, *names: str, default: DefaultT) -> float | DefaultT

Overload: return the typed default when no name resolves to a float.

raw_float​

def raw_float(raw: object,
*names: str,
default: DefaultT | None = None) -> float | DefaultT | None

Read the first name that resolves to a float from a raw model or mapping.

Delegates to raw_get, then applies a runtime isinstance check. A non-bool int is accepted and widened via float() so that JSON integers land cleanly in float-typed fields. A bool is not accepted (bool is an int subclass but never a meaningful number here). Mirrors raw_get's lenient contract, so a wrong-typed value is treated as absent rather than raising.

Arguments:

  • raw - Generated model or mapping to inspect.
  • *names - Candidate attribute or key names to try in order.
  • default - Fallback returned when no name resolves to a float or int.

Returns:

The first resolved float value (integers widened via float()), or default.

raw_bool​

@overload
def raw_bool(raw: object, *names: str) -> bool | None

Overload: return None when no name resolves to a bool.

raw_bool​

@overload
def raw_bool(raw: object, *names: str, default: DefaultT) -> bool | DefaultT

Overload: return the typed default when no name resolves to a bool.

raw_bool​

def raw_bool(raw: object,
*names: str,
default: DefaultT | None = None) -> bool | DefaultT | None

Read the first name that resolves to a bool from a raw model or mapping.

Delegates to raw_get, then applies a runtime isinstance check. Only a true bool matches; integers such as 0/1 are not coerced. Mirrors raw_get's lenient contract, so a wrong-typed value is treated as absent rather than raising.

Arguments:

  • raw - Generated model or mapping to inspect.
  • *names - Candidate attribute or key names to try in order.
  • default - Fallback returned when no name resolves to a bool.

Returns:

The first resolved bool value, or default.

raw_list​

@overload
def raw_list(raw: object, *names: str) -> list[object] | None

Overload: return None when no name resolves to a list.

raw_list​

@overload
def raw_list(raw: object, *names: str,
default: DefaultT) -> list[object] | DefaultT

Overload: return the typed default when no name resolves to a list.

raw_list​

def raw_list(
raw: object,
*names: str,
default: DefaultT | None = None) -> list[object] | DefaultT | None

Read the first name that resolves to a list from a raw model or mapping.

Delegates to raw_get, then applies a runtime isinstance check. Only a list matches; tuples and other sequences are treated as a type mismatch. Mirrors raw_get's lenient contract, so a wrong-typed value is treated as absent rather than raising.

Arguments:

  • raw - Generated model or mapping to inspect.
  • *names - Candidate attribute or key names to try in order.
  • default - Fallback returned when no name resolves to a list.

Returns:

The first resolved list value, or default.

raw_mapping​

@overload
def raw_mapping(raw: object, *names: str) -> Mapping[str, object] | None

Overload: return None when no name resolves to a Mapping.

raw_mapping​

@overload
def raw_mapping(raw: object, *names: str,
default: DefaultT) -> Mapping[str, object] | DefaultT

Overload: return the typed default when no name resolves to a Mapping.

raw_mapping​

def raw_mapping(
raw: object,
*names: str,
default: DefaultT | None = None
) -> Mapping[str, object] | DefaultT | None

Read the first name that resolves to a Mapping from a raw model or mapping.

Delegates to raw_get, then applies a runtime isinstance check against collections.abc.Mapping (so plain dict and other mapping types both match). Mirrors raw_get's lenient contract, so a wrong-typed value is treated as absent rather than raising.

Arguments:

  • raw - Generated model or mapping to inspect.
  • *names - Candidate attribute or key names to try in order.
  • default - Fallback returned when no name resolves to a Mapping.

Returns:

The first resolved Mapping value, or default.

raw_to_python​

def raw_to_python(value: object) -> PythonValue

Deep-convert generated models and Unset values into plain Python data.

Arguments:

  • value - Generated model, container, or scalar value to normalize.

Returns:

A deep-copied Python value composed of built-in containers and scalars.

RawBackedHandle Objects​

class RawBackedHandle()

Mixin for lightweight wrappers backed by a raw generated payload.

Subclasses store the underlying model on an attribute named _raw (the default; override _raw_attr to use a different attribute name). The handle then exposes:

  • raw gives direct access to the original generated model or mapping.
  • raw_dict returns a deep, JSON-friendly copy via raw_to_python.

The class itself is rarely instantiated directly; it is mixed into handle dataclasses such as sasvi.Document and sasvi.Alert.

raw​

@property
def raw() -> object

The underlying generated or mapping payload.

raw_dict​

def raw_dict() -> PythonValue

Return the raw payload converted into plain Python data.