base
MLTE general store interface.
ManagedSession
A simple context manager for store sessions.
Source code in mlte/store/base.py
189 190 191 192 193 194 195 196 197 198 199 200 | |
session = session
instance-attribute
The wrapped session.
ResourceMapper
Bases: ABC
A generic interface for mapping CRUD actions to store specific resources.
Source code in mlte/store/base.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
DEFAULT_LIST_LIMIT = 100
class-attribute
instance-attribute
Default limit for lists.
NOT_IMPLEMENTED_ERROR_MSG = 'Cannot invoke method that has not been implemented for this mapper.'
class-attribute
instance-attribute
Default error message for this abstract class.
validators = validators
instance-attribute
A reference to the store validators.
create(new_resource, context)
abstractmethod
Create a new resource. :throws: ErrorAlreadyExists if found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_resource
|
Any
|
The data to create the resource |
required |
context
|
Any
|
Any additional context needed for this resource. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The created resource |
Source code in mlte/store/base.py
220 221 222 223 224 225 226 227 228 229 | |
delete(resource_identifier, context)
abstractmethod
Delete a resource. :throws: ErrorNotFound if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_identifier
|
str
|
The identifier for the resource |
required |
context
|
Any
|
Any additional context needed for this resource. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The deleted resource |
Source code in mlte/store/base.py
262 263 264 265 266 267 268 269 270 271 | |
edit(updated_resource, context)
abstractmethod
Edit an existing resource. :throws: ErrorNotFound if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
updated_resource
|
Any
|
The data to edit the resource |
required |
context
|
Any
|
Any additional context needed for this resource. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The edited resource |
Source code in mlte/store/base.py
231 232 233 234 235 236 237 238 239 240 | |
list(context)
abstractmethod
List all resources of this type in the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Any
|
Any additional context needed for this resource. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
A collection of identifiers for all resources of this type |
Source code in mlte/store/base.py
253 254 255 256 257 258 259 260 | |
list_details(context=None, limit=DEFAULT_LIST_LIMIT, offset=0)
Read details of resources within limit and offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Any
|
Any additional context needed for this resource. |
None
|
limit
|
int
|
The limit on resources to read |
DEFAULT_LIST_LIMIT
|
offset
|
int
|
The offset on resources to read |
0
|
Returns:
| Type | Description |
|---|---|
List[Any]
|
The read resources |
Source code in mlte/store/base.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
read(resource_identifier, context)
abstractmethod
Read a resource. :throws: ErrorNotFound if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_identifier
|
str
|
The identifier for the resource |
required |
context
|
Any
|
Any additional context needed for this resource. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The resource |
Source code in mlte/store/base.py
242 243 244 245 246 247 248 249 250 251 | |
search(query, context=None)
Read a collection of resources, optionally filtered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Query
|
The resource query to apply |
required |
context
|
Any
|
Any additional context needed for this resource. |
None
|
Returns:
| Type | Description |
|---|---|
List[Any]
|
A collection of resources that satisfy the filter |
Source code in mlte/store/base.py
291 292 293 294 295 296 297 298 299 300 | |
Store
An abstract store. A Store instance is the "static" part of a store configuration. In contrast, a StoreSession represents an active session with the store.
Source code in mlte/store/base.py
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 | |
uri = uri
instance-attribute
The parsed store URI.
validators = CompositeValidator()
instance-attribute
The inter store validators for this store.
__init__(*, uri)
Initialize a Store instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
StoreURI
|
The parsed store URI |
required |
Source code in mlte/store/base.py
153 154 155 156 157 158 159 160 161 162 163 | |
session()
Return a session handle for the store instance.
Returns:
| Type | Description |
|---|---|
StoreSession
|
The session handle |
Source code in mlte/store/base.py
168 169 170 171 172 173 | |
StoreSession
Bases: Protocol
The base class for all implementations of the MLTE store session.
Source code in mlte/store/base.py
181 182 183 184 185 186 | |
close()
Close the session.
Source code in mlte/store/base.py
184 185 186 | |
StoreType
Bases: Enum
Represents the type of an MLTE store.
Source code in mlte/store/base.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
LOCAL_FILESYSTEM = 'local_filesystem'
class-attribute
instance-attribute
A local filesystem implementation.
LOCAL_MEMORY = 'local_memory'
class-attribute
instance-attribute
An in-memory store implementation.
RELATIONAL_DB = 'database'
class-attribute
instance-attribute
A relational database system implementation.
REMOTE_HTTP = 'remote_http'
class-attribute
instance-attribute
A remote HTTP implementation.
StoreURI
Represents the URI for an store instance.
Source code in mlte/store/base.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 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 | |
DEFAULT_STORES_FOLDER = 'default_store'
class-attribute
instance-attribute
Default root folder for all built-in file-based stores.
DELIMITER = '://'
class-attribute
instance-attribute
Delimiter used to separate prefixes from rest of the path.
PREFIXES = {StoreType.LOCAL_MEMORY: ['memory'], StoreType.LOCAL_FILESYSTEM: ['fs', 'local'], StoreType.REMOTE_HTTP: ['http'], StoreType.RELATIONAL_DB: ['sqlite', 'mysql', 'postgresql', 'oracle', 'mssql']}
class-attribute
instance-attribute
Valid prefixes by store type.
path = path
instance-attribute
The rest of the path, with the prefix removed.
prefix = prefix
instance-attribute
The actual prefix used in the type.
type = type
instance-attribute
The type identifier for the URI.
uri = uri
instance-attribute
The string that represents the URI.
__init__(uri, type, path, prefix)
Initialize a StoreURI instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
The URI |
required |
type
|
StoreType
|
The type of the backend store |
required |
path
|
str
|
The rest of the URI's path with the prefix removed |
required |
Source code in mlte/store/base.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
create_default_fs_uri()
staticmethod
Creates the default StoreURI for file system stores.
Source code in mlte/store/base.py
129 130 131 132 133 134 135 136 | |
create_uri_string(type, path='')
staticmethod
Creates a URI using the default (first) prefix for the given type.
Source code in mlte/store/base.py
123 124 125 126 127 | |
from_string(uri)
staticmethod
Parse a StoreURI from a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
The URI |
required |
Returns:
| Type | Description |
|---|---|
StoreURI
|
The parsed StoreURI |
Source code in mlte/store/base.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
from_type(type, path='')
staticmethod
Creates a parsed StoreURI from the given type, and optional path.
Source code in mlte/store/base.py
96 97 98 99 | |
get_type(prefix)
staticmethod
Returns the type given a prefix.
Source code in mlte/store/base.py
101 102 103 104 105 106 107 108 109 | |