base
mlte/store/base.py
MLTE general store interface.
ManagedSession
A simple context manager for store sessions.
Source code in mlte/store/base.py
153 154 155 156 157 158 159 160 161 162 163 164 |
|
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
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 201 202 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 |
|
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.
create(new_resource, context=None)
abstractmethod
Create a new resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_resource
|
Any
|
The data to create the resource |
required |
context
|
Any
|
Any additional context needed for this resource. |
None
|
Returns:
Type | Description |
---|---|
Any
|
The created resource |
Source code in mlte/store/base.py
180 181 182 183 184 185 186 187 188 |
|
delete(resource_identifier, context=None)
abstractmethod
Delete a resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_identifier
|
str
|
The identifier for the resource |
required |
context
|
Any
|
Any additional context needed for this resource. |
None
|
Returns:
Type | Description |
---|---|
Any
|
The deleted resource |
Source code in mlte/store/base.py
219 220 221 222 223 224 225 226 227 |
|
edit(updated_resource, context=None)
abstractmethod
Edit an existing resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
updated_resource
|
Any
|
The data to edit the resource |
required |
context
|
Any
|
Any additional context needed for this resource. |
None
|
Returns:
Type | Description |
---|---|
Any
|
The edited resource |
Source code in mlte/store/base.py
190 191 192 193 194 195 196 197 198 |
|
list(context=None)
abstractmethod
List all resources of this type in the store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
Any
|
Any additional context needed for this resource. |
None
|
Returns:
Type | Description |
---|---|
List[str]
|
A collection of identifiers for all resources of this type |
Source code in mlte/store/base.py
210 211 212 213 214 215 216 217 |
|
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
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
read(resource_identifier, context=None)
abstractmethod
Read a resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_identifier
|
str
|
The identifier for the resource |
required |
context
|
Any
|
Any additional context needed for this resource. |
None
|
Returns:
Type | Description |
---|---|
Any
|
The resource |
Source code in mlte/store/base.py
200 201 202 203 204 205 206 207 208 |
|
search(query=Query(), context=None)
Read a collection of resources, optionally filtered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Query
|
The resource query to apply |
Query()
|
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
247 248 249 250 251 252 253 254 255 256 |
|
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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
uri = uri
instance-attribute
The parsed store URI.
__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
123 124 125 126 127 128 129 130 |
|
session()
Return a session handle for the store instance.
Returns:
Type | Description |
---|---|
StoreSession
|
The session handle |
Source code in mlte/store/base.py
132 133 134 135 136 137 |
|
StoreSession
Bases: Protocol
The base class for all implementations of the MLTE store session.
Source code in mlte/store/base.py
145 146 147 148 149 150 |
|
close()
Close the session.
Source code in mlte/store/base.py
148 149 150 |
|
StoreType
Bases: Enum
Represents the type of an MLTE store.
Source code in mlte/store/base.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
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
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 |
|
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.
type = type
instance-attribute
The type identifier for the URI.
uri = uri
instance-attribute
The string that represents the URI.
__init__(uri, type, path)
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 |
|
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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
get_default_prefix(type)
staticmethod
Returns the default prefix for the given type, which will be the first one.
Source code in mlte/store/base.py
103 104 105 106 |
|