bayesline.api.equity.AsyncRiskDatasetLoaderApi#

class bayesline.api.equity.AsyncRiskDatasetLoaderApi#

API for loading and managing risk datasets.

This class provides functionality for loading, creating, and managing risk datasets through a registry-based approach. self.settings is a registry view over the discriminated union AnyRiskDatasetSettings — both reference-based DerivedRiskDatasetSettings and root RootRiskDatasetSettings are addressable through the same handle.

__init__()#

Methods

__init__()

create_dataset(name, settings)

Create a new dataset with the given name and settings.

create_dataset_as_task(name, settings)

create_or_replace_dataset(name, settings)

Create a new dataset or replace an existing one.

delete_dataset(name)

Delete the given dataset.

delete_dataset_if_exists(name)

Delete the given dataset if it exists.

get_dataset_names(*[, mode])

Get the names of all available datasets.

get_dataset_status(name)

Return the status of a single dataset.

list_riskdatasets([name, df])

List all available risk datasets.

load(ref_or_settings, *args, **kwargs)

Load an API instance from settings or reference.

validate(settings)

Validate settings against the menu for its dataset.

Attributes

settings

Get the settings registry.

abstract async get_dataset_names(*, mode: Literal['System', 'User'] | None = None) dict[str, Literal['ready', 'data_stale', 'needs_update', 'not_ready', 'corrupt']]#

Get the names of all available datasets.

Datasets owned by the current user are exposed under both their email-qualified name (alice@example.com/MyDS) and a bare alias (MyDS), mapping to the same status. This is intentional — it lets callers look up a dataset by either form against the returned dict (the status-fetch helpers in calendar, universe, exposures, portfolios rely on this). Callers iterating len(...), sorted(...), or building counts from the result should treat the dual-key entries as one logical dataset.

Parameters#

modeLiteral[“System”, “User”] | None, default=None

System: only system wide datasets (available to all users and provided by the system). User: only user specific datasets (available to the current user). None: all datasets (system wide and user specific).

Returns#

dict[str, DatasetStatus]

The names of all available datasets and their status. “ready” means the dataset is ready to use. “data_stale” means the dataset is ready to use but newer data is available. “needs_update” means local data needs to be computed/updated. “not_ready” means the reference dataset is not in a usable state. “corrupt” means the underlying settings are corrupted and need to be repaired.

async get_dataset_status(name: str) Literal['ready', 'data_stale', 'needs_update', 'not_ready', 'corrupt']#

Return the status of a single dataset.

Defaults to indexing get_dataset_names(); implementations may override to resolve a single dataset’s status without computing the status of every dataset.

Parameters#

namestr

Name of the dataset (bare alias or email-qualified).

Returns#

DatasetStatus

The status of the dataset. See get_dataset_names() for the meaning of each value.

Raises#

KeyError

If name is not a known dataset.

abstract async list_riskdatasets(name: str | None = None, *, df: bool = False) list[RiskDatasetMetadata] | DataFrame#

List all available risk datasets.

Parameters#

namestr | None, default=None

The name of the dataset to filter by. If not given, all datasets are returned.

dfbool, default=False

If True, return a polars DataFrame instead of a list of metadata objects.

Returns#

list[RiskDatasetMetadata] | pl.DataFrame

The metadata of all available datasets, either as a list of objects or as a DataFrame depending on the df parameter.

async create_or_replace_dataset(name: str, settings: Annotated[DerivedRiskDatasetSettings | RootRiskDatasetSettings, Discriminator(discriminator=kind, custom_error_type=None, custom_error_message=None, custom_error_context=None)]) AsyncRiskDatasetApi#

Create a new dataset or replace an existing one.

Parameters#

namestr

The name of the dataset to create or replace.

settingsAnyRiskDatasetSettings

The settings for the dataset. Pass DerivedRiskDatasetSettings for a reference-based dataset; pass RootRiskDatasetSettings for a root dataset built from upload sources.

Returns#

AsyncRiskDatasetApi

The API for the created or replaced dataset.

abstract async create_dataset(name: str, settings: Annotated[DerivedRiskDatasetSettings | RootRiskDatasetSettings, Discriminator(discriminator=kind, custom_error_type=None, custom_error_message=None, custom_error_context=None)]) AsyncRiskDatasetApi#

Create a new dataset with the given name and settings.

Parameters#

namestr

The name of the dataset to create.

settingsAnyRiskDatasetSettings

The settings for the dataset to create. Pass DerivedRiskDatasetSettings for a reference-based dataset; pass RootRiskDatasetSettings for a root dataset built from upload sources. Dispatch is by isinstance of the settings type.

Raises#

DatasetError

If a dataset with the given name already exists or if the settings are otherwise invalid.

Returns#

AsyncRiskDatasetApi

The API of the newly created dataset.

abstract async create_dataset_as_task(name: str, settings: Annotated[DerivedRiskDatasetSettings | RootRiskDatasetSettings, Discriminator(discriminator=kind, custom_error_type=None, custom_error_message=None, custom_error_context=None)]) AsyncTask[AsyncRiskDatasetApi]#
abstract async delete_dataset(name: str) RawSettings#

Delete the given dataset.

Parameters#

namestr

The name of the dataset to delete.

Raises#

KeyError

If the dataset does not exist.

DatasetError

If the dataset could not be deleted.

Returns#

RawSettings

The raw settings of the deleted dataset.

async delete_dataset_if_exists(name: str) RawSettings | None#

Delete the given dataset if it exists.

Parameters#

namestr

The name of the dataset to delete.

Raises#

DatasetError

If the dataset could not be deleted.

Returns#

RawSettings | None

The raw settings of the deleted dataset if dataset existed.