Drop
A Drop in a Bucket
is a reference to a resource.
class Drop
dataclass
#
Bases: Generic[KeyT]
A drop is a reference to a resource in a bucket.
You likely do not need to create these yourself and
are a class used by Bucket to wrap
access to a resource located at a give key.
The main use of this class is to attempt to use different
loaders to load a resource
at a given key, using the key to try infer which loader
to use. Each drop has a list of default loaders that it will
try to use to load the resource.
For flexibility, you can also specify a how when using any
of load, get
or put to override the default loaders.
The remove and
exists method also has a how
incase the default methods are not sufficient.
To support well typed code, you can also specify a check type
which will be used to checked when loading objects, to make sure
it is of the correct type. This is ignored if how is specified.
The primary methods of interest are
* load
* get
* put
* remove
* exists
* as_stored_value
| PARAMETER | DESCRIPTION |
|---|---|
key |
The key to the resource.
TYPE:
|
loaders |
The loaders to use to load the resource.
TYPE:
|
def as_stored_value(read=None)
#
Convert the drop to a StoredValue.
| PARAMETER | DESCRIPTION |
|---|---|
read |
The method to use to load the resource. If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StoredValue[KeyT, T]
|
The drop as a |
Source code in src/amltk/store/drop.py
def put(obj, *, how=None)
#
Put an object into the bucket.
| PARAMETER | DESCRIPTION |
|---|---|
obj |
The object to put into the bucket.
TYPE:
|
how |
The function to use to put the object into the bucket.
If
TYPE:
|
Source code in src/amltk/store/drop.py
def load(*, check=None, how=None)
#
Load the resource.
| PARAMETER | DESCRIPTION |
|---|---|
check |
By specifying a
TYPE:
|
how |
The function to use to load the resource.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
T | Any
|
The loaded resource. |
Source code in src/amltk/store/drop.py
def get(default=None, *, check=None, how=None)
#
Load the resource, or return the default if it can't be loaded.
See load for more details.
Note
This function makes no distinction for the reason it fails to load, namely if it's of the incorrect type or the resource does not exist at the key.
| PARAMETER | DESCRIPTION |
|---|---|
default |
The default value to return if the resource can't be loaded.
TYPE:
|
check |
By specifying a
TYPE:
|
how |
The function to use to load the resource.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Default | T | None
|
The loaded resource or the default value if it cant be loaded. |
Source code in src/amltk/store/drop.py
def remove(*, how=None)
#
Remove the resource from the bucket.
| PARAMETER | DESCRIPTION |
|---|---|
how |
The function to use to remove the resource. Returns Non-existent resources If the resource does not exist, then the function will |