sasvi.reference_lists
Public surface for the reference-lists feature layer.
Re-exports the reference-list and item record types, the validation
issue/result types, and the ReferenceListsService handle so callers
can import them from sasvi.reference_lists without reaching into private
submodules.
Handwritten service and bound records for reference lists.
Lists, fetches, creates, and mutates Data Hub reference lists and their items,
exposing autosaving bound records plus value-validation helpers. Validation
misses raise sasvi.errors.ReferenceListValidationError; malformed item
inputs raise sasvi.errors.AdminOperationError; a stale-snapshot write
conflict (If-Match precondition failure) raises
sasvi.errors.ReferenceListConcurrentModificationError; and Data Hub call
failures surface via ensure_datahub_success as
sasvi.errors.DocumentOperationError.
ReferenceListValidationIssue Objects
@dataclass(frozen=True, slots=True)
class ReferenceListValidationIssue()
One reference-list validation miss or duplicate input value.
value
count
to_dict
def to_dict() -> JsonObject
Return a JSON-serializable snapshot of the validation issue.
ReferenceListValidationResult Objects
@dataclass(frozen=True, slots=True)
class ReferenceListValidationResult()
Result of validating values against a reference-list lookup.
Use bool(result) for a quick pass/fail check, result.missing_values
and result.duplicate_values for compact lists, and
result.raise_for_invalid() to abort early when any input was invalid.
valid
checked_count
missing
duplicates
missing_values
@property
def missing_values() -> list[object]
Convenience accessor: list of values that were not found.
duplicate_values
@property
def duplicate_values() -> list[object]
Convenience accessor: list of values that occurred more than once.
raise_for_invalid
def raise_for_invalid() -> None
Raise ReferenceListValidationError when validation failed.
Pattern matching raise_for_status(): use to abort an ingestion
pipeline immediately on bad input.
to_dict
def to_dict() -> JsonObject
Return a JSON-serializable snapshot of the validation result.
ReferenceListItemInput Objects
@dataclass(frozen=True, slots=True)
class ReferenceListItemInput()
Handwritten input model for normal reference-list items.
code
label
description
archived
localized_labels
additional_properties
to_dict
def to_dict() -> JsonObject
Return a JSON-serializable constructor snapshot.
raw_dict
def raw_dict() -> JsonObject
Return the Data Hub item payload.
ReferenceListItemRecord Objects
class ReferenceListItemRecord(RawBackedHandle)
Read-only view of one reference-list item.
Arguments:
raw- Generated reference-list item payload.
id
@property
def id() -> int | None
The item's server-assigned id, or None if it is unsaved.
code
@property
def code() -> str | None
The item's code -- its stored lookup value -- or None if unset.
label
@property
def label() -> str | None
The item label.
Returns:
The item label, or None when the item is unlabeled.
description
@property
def description() -> str | None
The item description.
Returns:
The item description, or None when absent.
archived
@property
def archived() -> bool
Whether the item is archived.
Returns:
True when the item is archived.
display_index
@property
def display_index() -> int | None
The item's display-order index, or None if unset.
to_dict
def to_dict() -> JsonObject
Return a JSON-serializable snapshot of the item.
ReferenceListItemsManager Objects
class ReferenceListItemsManager()
Mutable helper for the items inside one bound reference list.
Arguments:
owner- Bound reference-list record that owns the items.
list
def list() -> list[ReferenceListItemRecord]
Return the current items as bound records.
list_async
async def list_async() -> builtins.list[ReferenceListItemRecord]
Asynchronously return the current items as bound records.
replace
def replace(items: builtins.list[str
| ReferenceListItem
| ReferenceListItemRecord
| ReferenceListItemInput
| Mapping[str, Any]],
*,
locale: str | None = None) -> ReferenceListRecord
Replace the full item collection on the parent reference list.
Arguments:
items- Replacement item payloads or records.locale- Locale that labels and descriptions are written for. By default it is the one the server showed, read off the list's texts.
Returns:
The updated parent reference-list record.
Raises:
AdminOperationError- If a label or description is written withoutlocaleand the list reads the same in several locales. Nothing is sent.
replace_async
async def replace_async(items: builtins.list[str
| ReferenceListItem
| ReferenceListItemRecord
| ReferenceListItemInput
| Mapping[str, Any]],
*,
locale: str | None = None) -> ReferenceListRecord
Asynchronously replace the full item collection.
Arguments:
items- Replacement item payloads or records.locale- Locale that labels and descriptions are written for. By default it is the one the server showed, read off the list's texts.
Returns:
The updated parent reference-list record.
Raises:
AdminOperationError- If a label or description is written withoutlocaleand the list reads the same in several locales. Nothing is sent.
append
def append(item: (str
| ReferenceListItem
| ReferenceListItemRecord
| ReferenceListItemInput
| Mapping[str, Any]),
*,
locale: str | None = None) -> ReferenceListRecord
Append one item and persist the updated reference list.
When an archived item carries the same code (the server archives a removed item rather than deleting it), that item is revived in place, keeping its id and display index, instead of a second entry being added.
Arguments:
item- Item payload or record to append.locale- Locale that labels and descriptions are written for. By default it is the one the server showed, read off the list's texts.
Returns:
The updated parent reference-list record.
Raises:
AdminOperationError- If a label or description is written withoutlocaleand the list reads the same in several locales. Nothing is sent.
append_async
async def append_async(item: (str
| ReferenceListItem
| ReferenceListItemRecord
| ReferenceListItemInput
| Mapping[str, Any]),
*,
locale: str | None = None) -> ReferenceListRecord
Asynchronously append one item and persist the updated reference list.
See append for how an archived item with the same code is revived.
Arguments:
item- Item payload or record to append.locale- Locale that labels and descriptions are written for. By default it is the one the server showed, read off the list's texts.
Returns:
The updated parent reference-list record.
Raises:
AdminOperationError- If a label or description is written withoutlocaleand the list reads the same in several locales. Nothing is sent.
upsert
def upsert(item: (str
| ReferenceListItem
| ReferenceListItemRecord
| ReferenceListItemInput
| Mapping[str, Any]),
*,
locale: str | None = None) -> ReferenceListRecord
Replace an existing item by code or append it when missing.
The replacement takes the existing item's place in the list and keeps its id, display index, label and description unless the input carries its own. An archived item with that code is revived the same way.
Arguments:
item- Item payload or record to upsert.locale- Locale that labels and descriptions are written for. By default it is the one the server showed, read off the list's texts.
Returns:
The updated parent reference-list record.
Raises:
AdminOperationError- If a label or description is written withoutlocaleand the list reads the same in several locales. Nothing is sent.
upsert_async
async def upsert_async(item: (str
| ReferenceListItem
| ReferenceListItemRecord
| ReferenceListItemInput
| Mapping[str, Any]),
*,
locale: str | None = None) -> ReferenceListRecord
Asynchronously replace an existing item by code or append it when missing.
See upsert for what the replacement keeps from the existing item.
Arguments:
item- Item payload or record to upsert.locale- Locale that labels and descriptions are written for. By default it is the one the server showed, read off the list's texts.
Returns:
The updated parent reference-list record.
Raises:
AdminOperationError- If a label or description is written withoutlocaleand the list reads the same in several locales. Nothing is sent.
remove
def remove(*, code: str) -> ReferenceListRecord
Remove the item with the given code and persist the updated list.
The item is left out of the list the SDK writes back. The server keeps
it and marks it archived rather than deleting it, so it still
appears in list with archived=True; to_lookup and
validate_values leave archived items out by default, and
append or upsert of the same code revives it.
Arguments:
code- Reference-list item code to remove.
Returns:
The updated parent reference-list record.
remove_async
async def remove_async(*, code: str) -> ReferenceListRecord
Asynchronously remove the item with the given code and persist the list.
See remove: the server archives the item rather than deleting it.
Arguments:
code- Reference-list item code to remove.
Returns:
The updated parent reference-list record.
ReferenceListRecord Objects
class ReferenceListRecord(RawBackedHandle)
Mutable bound reference-list record.
Arguments:
datahub_api- Generated Data Hub API namespace used for list operations.name- Reference-list name.raw- Optional generated reference-list snapshot.
items
name
@property
def name() -> str
The reference-list name -- its stable tenant-unique identifier.
label
@property
def label() -> str | None
The list label.
Returns:
The list label, or None when unlabeled.
description
@property
def description() -> str | None
The list description.
Returns:
The list description, or None when absent.
archived
@property
def archived() -> bool
Whether the list is archived.
Returns:
True when the list is archived.
max_code_length
@property
def max_code_length() -> int | None
The maximum allowed code length.
Returns:
The configured maximum code length, or None when unspecified.
alphabetical_sort
@property
def alphabetical_sort() -> bool
Whether the list sorts alphabetically.
Returns:
True when alphabetical sorting is enabled.
refresh
def refresh() -> ReferenceListRecord
Reload the reference-list snapshot from the service.
refresh_async
async def refresh_async() -> ReferenceListRecord
Asynchronously reload the reference-list snapshot from the service.
update_metadata
def update_metadata(*,
locale: str | None = None,
**changes: Any) -> ReferenceListRecord
Update editable reference-list metadata fields.
Arguments:
locale- Locale a label or description is written for. By default it is the one the server showed, read off the list's texts.**changes- Editable metadata fields such aslabelordescription. A label or description keeps its other locales.Noneremoves it.alphabetical_sort=Truealso clears the items' display order, which the server requires.
Returns:
The updated bound reference-list record.
Raises:
AdminOperationError- If a label or description is written withoutlocaleand the list reads the same in several locales. Nothing is sent.
update_metadata_async
async def update_metadata_async(*,
locale: str | None = None,
**changes: Any) -> ReferenceListRecord
Asynchronously update editable reference-list metadata fields.
Arguments:
locale- Locale a label or description is written for. By default it is the one the server showed, read off the list's texts.**changes- Editable metadata fields such aslabelordescription. A label or description keeps its other locales.Noneremoves it.alphabetical_sort=Truealso clears the items' display order, which the server requires.
Returns:
The updated bound reference-list record.
Raises:
AdminOperationError- If a label or description is written withoutlocaleand the list reads the same in several locales. Nothing is sent.
item
def item(code: str) -> ReferenceListItemRecord | None
Return one item by code.
Archived items are returned too: check item.archived when a code
retired with items.remove must not count as present.
Arguments:
code- Reference-list item code.
Returns:
The matching item record, or None when not found.
Raises:
ReferenceListNotFoundError- When the record has not loaded its items and the list no longer exists.
item_async
async def item_async(code: str) -> ReferenceListItemRecord | None
Asynchronously return one item by code.
Reads the items the record already holds. A record that has not loaded
its items (one from a listing, or after a write) awaits one read of
the list first, exactly as item reads it synchronously.
Archived items are returned too.
Arguments:
code- Reference-list item code.
Returns:
The matching item record, or None when not found.
Raises:
ReferenceListNotFoundError- When the record has not loaded its items and the list no longer exists.
to_lookup
def to_lookup(*,
by: str = "code",
include_archived: bool = False) -> dict[str, str]
Return a simple code/label lookup for the reference list.
Arguments:
by- Lookup direction."code"returns{code: label};"label"returns{label: code}.include_archived- Whether archived items are part of the lookup. They are left out by default, because a code retired withitems.removestays on the server as archived.
Returns:
A dictionary useful for validation and import workflows.
Raises:
ReferenceListValidationError- Whenbyis not"code"or"label".AdminOperationError- When two items share thebyvalue, so the lookup would be ambiguous.
to_lookup_async
async def to_lookup_async(*,
by: str = "code",
include_archived: bool = False) -> dict[str, str]
Asynchronously return a simple code/label lookup for the reference list.
A record that has not loaded its items awaits one read of the list
first, exactly as to_lookup reads it synchronously.
Arguments:
by- Lookup direction."code"returns{code: label};"label"returns{label: code}.include_archived- Whether archived items are part of the lookup. They are left out by default, because a code retired withitems.removestays on the server as archived.
Returns:
A dictionary useful for validation and import workflows.
Raises:
ReferenceListValidationError- Whenbyis not"code"or"label". Nothing is sent.AdminOperationError- When two items share thebyvalue, so the lookup would be ambiguous.
validate_values
def validate_values(
values: Sequence[Any],
*,
by: str = "code",
case_sensitive: bool = True,
include_archived: bool = False) -> ReferenceListValidationResult
Validate incoming values against reference-list item codes or labels.
Arguments:
values- Incoming codes or labels to validate.by- Validate against"code"or"label"values.case_sensitive- Whether comparisons preserve case.include_archived- Whether an archived item's value counts as valid. It does not by default, because a code retired withitems.removestays on the server as archived.
Returns:
A structured validation result containing missing and duplicate inputs.
Raises:
ReferenceListValidationError- Whenbyis not"code"or"label".AdminOperationError- When two items share thebyvalue (labels are not unique on the server), so no lookup can be built.
validate_values_async
async def validate_values_async(
values: Sequence[Any],
*,
by: str = "code",
case_sensitive: bool = True,
include_archived: bool = False) -> ReferenceListValidationResult
Asynchronously validate values against reference-list item codes or labels.
A record that has not loaded its items awaits one read of the list
first, exactly as validate_values reads it synchronously. The
check itself is local.
Arguments:
values- Incoming codes or labels to validate.by- Validate against"code"or"label"values.case_sensitive- Whether comparisons preserve case.include_archived- Whether an archived item's value counts as valid. It does not by default, because a code retired withitems.removestays on the server as archived.
Returns:
A structured validation result containing missing and duplicate inputs.
Raises:
ReferenceListValidationError- Whenbyis not"code"or"label". Nothing is sent.AdminOperationError- When two items share thebyvalue (labels are not unique on the server), so no lookup can be built.
to_dict
def to_dict() -> JsonObject
Return a JSON-serializable snapshot of what this record has loaded.
Serializing sends no requests. Fields the record has not loaded are
None rather than fabricated, and items is None rather than an
empty list. Call
refresh (or refresh_async) first for the full picture.
Returns:
The loaded reference-list state.
ReferenceListsService Objects
class ReferenceListsService()
Service for listing, fetching, and creating reference lists.
Arguments:
datahub_api- Generated Data Hub API namespace used for list operations.
list
def list(*,
page_size: int = 1000,
max_items: int | None = None) -> list[ReferenceListRecord]
List available reference lists as bound records.
Arguments:
page_size- Number of summaries to request per page.max_items- Optional maximum number of records to return.
Returns:
Bound reference-list records visible to the current user.
Raises:
ReferenceListValidationError- Whenpage_sizeormax_itemsis not positive.IncompleteListingError- When the listing cannot be finished because the server stopped advancing or the page cap was reached. The offset to resume from is on the error.
list_async
async def list_async(
*,
page_size: int = 1000,
max_items: int | None = None) -> builtins.list[ReferenceListRecord]
Asynchronously list available reference lists as bound records.
Arguments:
page_size- Number of summaries to request per page.max_items- Optional maximum number of records to return.
Returns:
Bound reference-list records visible to the current user.
Raises:
ReferenceListValidationError- Whenpage_sizeormax_itemsis not positive.IncompleteListingError- When the listing cannot be finished because the server stopped advancing or the page cap was reached. The offset to resume from is on the error.
list_all
def list_all(
*,
page_size: int = 1000,
max_items: int | None = None) -> builtins.list[ReferenceListRecord]
Alias for list with explicit paging controls.
Arguments:
page_size- Number of reference lists to request per page.max_items- Optional maximum number of records to return.
list_all_async
async def list_all_async(
*,
page_size: int = 1000,
max_items: int | None = None) -> builtins.list[ReferenceListRecord]
Async alias for list_async with explicit paging controls.
Arguments:
page_size- Number of reference lists to request per page.max_items- Optional maximum number of records to return.
get
def get(*, name: str) -> ReferenceListRecord | None
Fetch a reference list by name.
Arguments:
name- Reference-list name.
Returns:
The bound reference-list record, or None when not found.
get_async
async def get_async(*, name: str) -> ReferenceListRecord | None
Asynchronously fetch a reference list by name.
Arguments:
name- Reference-list name.
Returns:
The bound reference-list record, or None when not found.
create
def create(*,
name: str,
archived: bool = False,
max_code_length: int = 50,
alphabetical_sort: bool = True,
label: str | None = None,
description: str | None = None,
items: Sequence[str
| ReferenceListItem
| ReferenceListItemRecord
| ReferenceListItemInput
| Mapping[str, Any]]
| None = None,
locale: str | None = _DEFAULT_LOCALE) -> ReferenceListRecord
Create a reference list.
Arguments:
name- Reference-list name.archived- Whether the list starts archived.max_code_length- Maximum allowed item-code length.alphabetical_sort- Whether the list should sort alphabetically.label- Optional display label.description- Optional description text.items- Optional initial item payloads. A code string gets the label the server makes from it.locale- Locale the labels and descriptions are written for. The tenant must support it. WithNonethey are sent without a locale, and the server ignores them.
Returns:
The created bound reference-list record.
create_async
async def create_async(
*,
name: str,
archived: bool = False,
max_code_length: int = 50,
alphabetical_sort: bool = True,
label: str | None = None,
description: str | None = None,
items: Sequence[str
| ReferenceListItem
| ReferenceListItemRecord
| ReferenceListItemInput
| Mapping[str, Any]]
| None = None,
locale: str | None = _DEFAULT_LOCALE) -> ReferenceListRecord
Asynchronously create a reference list.
Arguments:
name- Reference-list name.archived- Whether the list starts archived.max_code_length- Maximum allowed item-code length.alphabetical_sort- Whether the list should sort alphabetically.label- Optional display label.description- Optional description text.items- Optional initial item payloads. A code string gets the label the server makes from it.locale- Locale the labels and descriptions are written for. The tenant must support it. WithNonethey are sent without a locale, and the server ignores them.
Returns:
The created bound reference-list record.
create_from_values
def create_from_values(
name: str,
values: Sequence[str],
*,
label: str | None = None,
description: str | None = None,
code_strategy: str = "upper_slug",
max_code_length: int = 50,
alphabetical_sort: bool = True,
archived: bool = False,
locale: str | None = _DEFAULT_LOCALE) -> ReferenceListRecord
Create a reference list from display values.
Arguments:
name- Reference-list name.values- Display labels to create as items.label- Optional list label. Defaults tonamefor localized labels.description- Optional description text.code_strategy- Strategy used to generate item codes:"label","lower","numeric", or"upper_slug".max_code_length- Maximum allowed item-code length.alphabetical_sort- Whether the list should sort alphabetically.archived- Whether the list starts archived.locale- Locale the labels and the description are written for. The tenant must support it. WithNonethey are sent without a locale, and the server ignores them.
Returns:
The created bound reference-list record.
Raises:
ReferenceListValidationError- Whencode_strategyis unknown. Nothing is sent.AdminOperationError- When a generated code is empty, too long or not unique. Nothing is sent.DocumentOperationError- When the server rejects the list.
create_from_values_async
async def create_from_values_async(
name: str,
values: Sequence[str],
*,
label: str | None = None,
description: str | None = None,
code_strategy: str = "upper_slug",
max_code_length: int = 50,
alphabetical_sort: bool = True,
archived: bool = False,
locale: str | None = _DEFAULT_LOCALE) -> ReferenceListRecord
Asynchronously create a reference list from display values.
Arguments:
name- Reference-list name.values- Display labels to create as items.label- Optional list label. Defaults tonamefor localized labels.description- Optional description text.code_strategy- Strategy used to generate item codes:"label","lower","numeric", or"upper_slug".max_code_length- Maximum allowed item-code length.alphabetical_sort- Whether the list should sort alphabetically.archived- Whether the list starts archived.locale- Locale the labels and the description are written for. The tenant must support it. WithNonethey are sent without a locale, and the server ignores them.
Returns:
The created bound reference-list record.
Raises:
ReferenceListValidationError- Whencode_strategyis unknown. Nothing is sent.AdminOperationError- When a generated code is empty, too long or not unique. Nothing is sent.DocumentOperationError- When the server rejects the list.
create_from_mapping
def create_from_mapping(
name: str,
items: Mapping[str, str],
*,
label: str | None = None,
description: str | None = None,
max_code_length: int = 50,
alphabetical_sort: bool = True,
archived: bool = False,
locale: str | None = _DEFAULT_LOCALE) -> ReferenceListRecord
Create a reference list from {code: label} items.
Arguments:
name- Reference-list name.items- Mapping of item codes to display labels. Insertion order is kept withalphabetical_sort=False.label- Optional list label. Defaults tonamefor localized labels.description- Optional description text.max_code_length- Maximum allowed item-code length.alphabetical_sort- Whether the list should sort alphabetically.archived- Whether the list starts archived.locale- Locale the labels and the description are written for. The tenant must support it. WithNonethey are sent without a locale, and the server ignores them.
Returns:
The created bound reference-list record.
Raises:
AdminOperationError- When a code is longer thanmax_code_length. Nothing is sent.DocumentOperationError- When the server rejects the list.
create_from_mapping_async
async def create_from_mapping_async(
name: str,
items: Mapping[str, str],
*,
label: str | None = None,
description: str | None = None,
max_code_length: int = 50,
alphabetical_sort: bool = True,
archived: bool = False,
locale: str | None = _DEFAULT_LOCALE) -> ReferenceListRecord
Asynchronously create a reference list from {code: label} items.
Arguments:
name- Reference-list name.items- Mapping of item codes to display labels. Insertion order is kept withalphabetical_sort=False.label- Optional list label. Defaults tonamefor localized labels.description- Optional description text.max_code_length- Maximum allowed item-code length.alphabetical_sort- Whether the list should sort alphabetically.archived- Whether the list starts archived.locale- Locale the labels and the description are written for. The tenant must support it. WithNonethey are sent without a locale, and the server ignores them.
Returns:
The created bound reference-list record.
Raises:
AdminOperationError- When a code is longer thanmax_code_length. Nothing is sent.DocumentOperationError- When the server rejects the list.