operonx.core.registry¶
Resource hub, configuration storage, and op registry.
ResourceHub¶
ResourceHub
¶
Centralized registry for managing application resources.
Features: - Lazy loading: resources are initialized on first access - Pluggable storage: YAML, JSON, or custom backend - Extensible: external packages register their configs and factories
Example
hub = ResourceHub.from_yaml("configs/resources.yaml") llm = hub.get("llm:gpt-4o") stt = hub.get("triton:stt")
Or use global hub¶
from operonx.core.registry import ResourceHub llm = ResourceHub.instance().get("llm:gpt-4o")
Initialize hub with storage backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage
|
ConfigStorage
|
Storage backend for configs |
required |
source_path
|
Optional[Path]
|
Absolute path of the file the storage was loaded
from (set by |
None
|
Source code in operonx/core/registry/resource_hub.py
Attributes¶
Functions¶
from_yaml
classmethod
¶
Create hub with YAML file storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to YAML config file |
required |
Returns:
| Type | Description |
|---|---|
ResourceHub
|
ResourceHub instance |
Source code in operonx/core/registry/resource_hub.py
from_json
classmethod
¶
Create hub with JSON file storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to JSON config file |
required |
Returns:
| Type | Description |
|---|---|
ResourceHub
|
ResourceHub instance |
Source code in operonx/core/registry/resource_hub.py
auto
classmethod
¶
Try to install ResourceHub from ./resources.yaml in CWD.
Behavior:
- If a hub is already installed, return it unchanged (idempotent).
- If ./resources.yaml exists, load it, install the singleton,
and return the new hub.
- If not found, emit a :class:ResourceHubWarning naming the path
checked and return None. No singleton is installed.
Never raises. The warning is the early signal that setup is incomplete; silent miss would defer the problem to first resource resolution.
Source code in operonx/core/registry/resource_hub.py
instance
classmethod
¶
Get the global ResourceHub singleton.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no hub has been loaded. The message points at
|
Source code in operonx/core/registry/resource_hub.py
set_instance
classmethod
¶
reset_instance
classmethod
¶
keys
¶
Return all registered keys (loads all configs from storage).
Source code in operonx/core/registry/resource_hub.py
has
¶
get
¶
Get resource instance by key (lazy load on first access).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Registry key of resource |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Initialized resource instance |
Raises:
| Type | Description |
|---|---|
KeyError
|
If key not found or resource failed to initialize.
The message includes |
EnvVarUnsetError
|
If the resource references a |
Source code in operonx/core/registry/resource_hub.py
get_config
¶
Get config object of resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Registry key |
required |
Returns:
| Type | Description |
|---|---|
YamlModel
|
Resource config |
Raises:
| Type | Description |
|---|---|
KeyError
|
If key not found |
Source code in operonx/core/registry/resource_hub.py
register
¶
Register new resource config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
YamlModel
|
Resource config object |
required |
registry_key
|
Optional[str]
|
Custom key (auto-generated if not provided) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Registry key used |
Source code in operonx/core/registry/resource_hub.py
remove
¶
Remove resource from registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Registry key to remove |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if removed, False if not found |
Source code in operonx/core/registry/resource_hub.py
clear
¶
Clear all resources from registry and storage.
close
¶
keycloak
¶
Get KeycloakTokenProvider by key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Keycloak config identifier (e.g., 'myapp') |
required |
Returns:
| Type | Description |
|---|---|
KeycloakTokenProvider
|
KeycloakTokenProvider instance with get_token() method |
Source code in operonx/core/registry/resource_hub.py
warmup
async
¶
Pre-warm a resource's connection (e.g. LLM prompt cache).
Forces lazy-load of the resource, then calls its warmup()
method if it exists. For LLM providers this typically sends a
minimal API request to establish the TCP+TLS connection and
optionally seed the server-side prompt cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Registry key (e.g. |
required |
**kwargs
|
Any
|
Passed to the resource's |
{}
|
Example::
hub = ResourceHub.instance()
await hub.warmup("llm:default", system_prompt=sys_prompt)
Source code in operonx/core/registry/resource_hub.py
health_check
¶
Check health of all or specified resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
Optional[List[str]]
|
Optional list of keys to check. If None, checks all. |
None
|
Returns:
| Type | Description |
|---|---|
HealthCheckResult
|
HealthCheckResult with status of each resource |
Example
result = hub.health_check() if not result.healthy: print(f"Unhealthy resources: {result.failed}")
Source code in operonx/core/registry/resource_hub.py
Errors and warnings¶
EnvVarUnsetError
¶
Bases: RuntimeError
Raised when a required ${VAR} reference cannot be resolved.
Subclasses RuntimeError so existing except RuntimeError callers
continue to work — this preserves backwards-compatible behavior with
the previous _raise_missing_env_vars helper.
ResourceHubWarning
¶
Bases: UserWarning
Warning emitted by ResourceHub setup (auto / from_yaml / bootstrap).
Subclassing UserWarning lets users silence ResourceHub-specific
warnings without muting unrelated UserWarning traffic::
import warnings
from operonx.core.registry import ResourceHubWarning
warnings.filterwarnings("ignore", category=ResourceHubWarning)
Bootstrap state¶
BOOTSTRAP_ENV_PATHS is populated by operonx.bootstrap
and surfaces in the EnvVarUnsetError message so you can see exactly which
.env paths were searched.