backends
backends ¶
FileBackend ¶
FileBackend(
base_dir: Union[str, Path],
create_if_missing: bool = True,
locks_dir: Optional[Union[str, Path]] = None,
)
Bases: ResultsBackend[T]
File-based implementation of ResultsBackend.
Stores results as JSON files in a hierarchical directory structure.
Initialize the FileBackend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_dir
|
Union[str, Path]
|
Base directory to store results |
required |
create_if_missing
|
bool
|
Whether to create the directory if it doesn't exist |
True
|
locks_dir
|
Optional[Union[str, Path]]
|
Directory to store lock files. If None, uses a system temp directory. |
None
|
Source code in src/results_manager/backends/file_backend.py
clear ¶
Clear all stored results.
Source code in src/results_manager/backends/file_backend.py
delete ¶
Delete a result by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_id
|
Union[str, List[str]]
|
Unique identifier or hierarchical path for the result |
required |
Returns:
Type | Description |
---|---|
bool
|
True if deleted, False if not found |
Source code in src/results_manager/backends/file_backend.py
exists ¶
Check if a result exists for the given ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_id
|
Union[str, List[str]]
|
Unique identifier or hierarchical path for the result |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the result exists, False otherwise |
Source code in src/results_manager/backends/file_backend.py
get ¶
get(
result_id: Union[str, List[str]],
model_class: Optional[Type[T]] = None,
namespace: Optional[str] = None,
) -> T
Retrieve a result by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_id
|
Union[str, List[str]]
|
Unique identifier or hierarchical path for the result |
required |
model_class
|
Optional[Type[T]]
|
Optional model class to validate against. If not provided, the stored model type will be used. |
None
|
namespace
|
Optional[str]
|
Optional namespace override to look for the model in |
None
|
Returns:
Type | Description |
---|---|
T
|
Pydantic model instance |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the result doesn't exist |
ValueError
|
If the model type is not registered |
ValidationError
|
If the data doesn't match the model schema |
Source code in src/results_manager/backends/file_backend.py
list_ids ¶
List all result IDs, optionally filtered by a prefix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix
|
Union[str, List[str]]
|
Optional prefix path to filter results |
None
|
Returns:
Type | Description |
---|---|
List[str]
|
List of result IDs |
Source code in src/results_manager/backends/file_backend.py
set ¶
set(
result_id: Union[str, List[str]],
data: BaseModel,
behavior: SetBehavior = RAISE_IF_EXISTS,
namespace: Optional[str] = None,
strict_namespace: bool = False,
) -> bool
Store a result with the given ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_id
|
Union[str, List[str]]
|
Unique identifier or hierarchical path for the result |
required |
data
|
BaseModel
|
Pydantic model instance to store |
required |
behavior
|
SetBehavior
|
How to handle existing data with the same ID |
RAISE_IF_EXISTS
|
namespace
|
Optional[str]
|
Optional namespace to store the model in |
None
|
strict_namespace
|
bool
|
If True, raises an error if model is in multiple namespaces |
False
|
Returns:
Type | Description |
---|---|
bool
|
True if data was written, False if skipped |
Source code in src/results_manager/backends/file_backend.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
ResultsBackend ¶
Abstract base class for results storage backends.
Implementations should provide storage and retrieval of Pydantic models based on unique IDs.
clear
abstractmethod
¶
delete
abstractmethod
¶
exists
abstractmethod
¶
Check if a result exists for the given ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_id
|
Union[str, List[str]]
|
Unique identifier or hierarchical path for the result |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the result exists, False otherwise |
Source code in src/results_manager/backends/base.py
get
abstractmethod
¶
get(
result_id: Union[str, List[str]],
model_class: Optional[Type[T]] = None,
namespace: Optional[str] = None,
) -> T
Retrieve a result by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_id
|
Union[str, List[str]]
|
Unique identifier or hierarchical path for the result |
required |
model_class
|
Optional[Type[T]]
|
Optional model class to validate against |
None
|
namespace
|
Optional[str]
|
Optional namespace to look in |
None
|
Returns:
Type | Description |
---|---|
T
|
Pydantic model instance |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the result doesn't exist |
ValueError
|
If the model type is not registered |
Source code in src/results_manager/backends/base.py
list_ids
abstractmethod
¶
set
abstractmethod
¶
set(
result_id: Union[str, List[str]],
data: BaseModel,
behavior: SetBehavior = RAISE_IF_EXISTS,
namespace: Optional[str] = None,
strict_namespace: bool = False,
) -> bool
Store a result with the given ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_id
|
Union[str, List[str]]
|
Unique identifier or hierarchical path for the result |
required |
data
|
BaseModel
|
Pydantic model instance to store |
required |
behavior
|
SetBehavior
|
How to handle existing data with the same ID |
RAISE_IF_EXISTS
|
namespace
|
Optional[str]
|
Optional namespace to store the model in |
None
|
strict_namespace
|
bool
|
If True, raises an error if model is in multiple namespaces |
False
|
Returns:
Type | Description |
---|---|
bool
|
True if data was written, False if skipped |
Raises:
Type | Description |
---|---|
FileExistsError
|
If data already exists (for RAISE_IF_EXISTS) or if different data exists (for RAISE_IF_DIFFERENT) |