anystore.store
Top-level store entrypoint
get_store(uri=None, settings=None, **kwargs)
cached
Short-hand initializer for a new store. The call is cached during runtime if input doesn't change.
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str | None
|
Store base uri, if relative it is considered as a local file store, otherwise the store backend is inferred from the scheme. If omitted, store is derived from settings defaults (taking current environment into account). |
None
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Returns:
Type | Description |
---|---|
BaseStore
|
A |
Source code in anystore/store/__init__.py
Base store interface
The store class provides the top-level interface regardless for the storage backend.
BaseStore
Bases: StoreModel
, AbstractBackend
Source code in anystore/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 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 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 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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
checksum(key, algorithm=DEFAULT_HASH_ALGORITHM, **kwargs)
Get the checksum for the value at the given key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
algorithm
|
str | None
|
Checksum algorithm from |
DEFAULT_HASH_ALGORITHM
|
**kwargs
|
Any
|
Pass through arguments to content retrieval |
{}
|
Returns:
Type | Description |
---|---|
str
|
The computed checksum |
Source code in anystore/store/base.py
delete(key, ignore_errors=False)
Delete the content at the given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
ignore_errors
|
bool
|
Ignore exceptions if deletion fails |
False
|
Source code in anystore/store/base.py
exists(key)
get(key, raise_on_nonexist=None, serialization_mode=None, deserialization_func=None, model=None, **kwargs)
Get a value from the store for the given key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
raise_on_nonexist
|
bool | None
|
Raise |
None
|
serialization_mode
|
Mode | None
|
Serialize result ("auto", "raw", "pickle", "json"), overrides store settings |
None
|
deserialization_func
|
Callable | None
|
Specific function to use (ignores
|
None
|
model
|
Model | None
|
Pydantic serialization model (ignores |
None
|
Returns:
Type | Description |
---|---|
Any
|
The (optionally serialized) value for the key |
Source code in anystore/store/base.py
info(key)
Get metadata for the given key
.
Returns:
Type | Description |
---|---|
Stats
|
Key metadata |
Source code in anystore/store/base.py
iterate_keys(prefix=None, exclude_prefix=None, glob=None)
Iterate through all the keys in the store based on given criteria. Criteria can be combined (e.g. include but exclude a subset).
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix
|
str | None
|
Include only keys with the given prefix (e.g. "foo/bar") |
None
|
exclude_prefix
|
str | None
|
Exclude keys with this prefix |
None
|
glob
|
str | None
|
Path-style glob pattern for keys to filter (e.g. "foo/*/.json") |
None
|
Returns:
Type | Description |
---|---|
None
|
The matching keys as a generator of strings |
Source code in anystore/store/base.py
open(key, mode=DEFAULT_MODE, **kwargs)
Open the given key similar to built-in open()
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
mode
|
str | None
|
Open mode ("rb", "wb", "r", "w") |
DEFAULT_MODE
|
**kwargs
|
Any
|
Pass through arguments to backend |
{}
|
Returns:
Type | Description |
---|---|
None
|
The open handler |
Source code in anystore/store/base.py
pop(key, *args, **kwargs)
Retrieve the value for the given key and remove it from the store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
*args
|
Any
|
Any valid arguments for the stores |
()
|
**kwargs
|
Any
|
Any valid arguments for the stores |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The (optionally serialized) value for the key |
Source code in anystore/store/base.py
put(key, value, serialization_mode=None, serialization_func=None, model=None, ttl=None, **kwargs)
Store a value at the given key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
value
|
Any
|
The content |
required |
serialization_mode
|
Mode | None
|
Serialize value prior to storing ("auto", "raw", "pickle", "json"), overrides store settings |
None
|
serialization_func
|
Callable | None
|
Specific function to use (ignores
|
None
|
model
|
Model | None
|
Pydantic serialization model (ignores |
None
|
ttl
|
int | None
|
Time to live (in seconds) for that key if the backend supports it (e.g. redis, sql) |
None
|
Source code in anystore/store/base.py
stream(key, raise_on_nonexist=None, serialization_mode=None, deserialization_func=None, model=None, **kwargs)
Stream a value line by line from the store for the given key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
raise_on_nonexist
|
bool | None
|
Raise |
None
|
serialization_mode
|
Mode | None
|
Serialize result ("auto", "raw", "pickle", "json"), overrides store settings |
None
|
deserialization_func
|
Callable | None
|
Specific function to use (ignores
|
None
|
model
|
Model | None
|
Pydantic serialization model (ignores |
None
|
Yields:
Type | Description |
---|---|
Any
|
The (optionally serialized) values line by line |
Raises:
Type | Description |
---|---|
DoesNotExists
|
If key doesn't exist and raise_on_nonexist=True |
Source code in anystore/store/base.py
touch(key, **kwargs)
Store the current timestamp at the given key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Uri
|
Key relative to store base uri |
required |
**kwargs
|
Any
|
Any valid arguments for the stores |
{}
|
Returns:
Type | Description |
---|---|
datetime
|
The timestamp |
Source code in anystore/store/base.py
VirtualIOMixin
Fake open()
method for non file-like backends
Source code in anystore/store/base.py
check_readonly(func)
Guard for read-only store. Write functions should be decorated with it
Source code in anystore/store/base.py
Models
Pydantic model interfaces to initialize stores and handle metadata for keys.
BaseStats
Bases: BaseModel
Shared base metadata object
Source code in anystore/model.py
created_at: datetime | None = None
class-attribute
instance-attribute
Created at timestamp
size: int
instance-attribute
Size (content length) in bytes
updated_at: datetime | None = None
class-attribute
instance-attribute
Last updated timestamp
Stats
Bases: BaseStats
Meta information for a store key
Source code in anystore/model.py
key: str
instance-attribute
Full path of key
name: str
instance-attribute
Key name: last part of the key (aka file name without path)
store: str
instance-attribute
Store base uri
uri: str
property
Computed uri property. Absolute when file-like prepended with store schema, relative if using different store backend
Returns:
Type | Description |
---|---|
str
|
file-like: |
str
|
relative path for other (redis, sql, ...): |
StoreModel
Bases: BaseModel
Store model to initialize a store from configuration
Source code in anystore/model.py
backend_config: dict[str, Any] | None = None
class-attribute
instance-attribute
Backend-specific configuration to pass through for initialization
default_ttl: int | None = settings.default_ttl
class-attribute
instance-attribute
Default ttl for keys (only backends that support it: redis, sql, ..)
deserialization_func: Callable | None = None
class-attribute
instance-attribute
Default deserialization function
is_fslike: bool
cached
property
Check if it is a file-like store usable with fsspec
is_local: bool
cached
property
Check if it is a local file store
is_sql: bool
cached
property
Check if it is a sql-like store (sqlite, postgres, ...)
model: Model | None = None
class-attribute
instance-attribute
Default pydantic model for serialization
raise_on_nonexist: bool | None = settings.raise_on_nonexist
class-attribute
instance-attribute
Raise anystore.exceptions.DoesNotExist
if key doesn't exist
readonly: bool | None = False
class-attribute
instance-attribute
Consider this store as a read-only store, writing will raise an exception
serialization_func: Callable | None = None
class-attribute
instance-attribute
Default serialization function
serialization_mode: Mode | None = settings.serialization_mode
class-attribute
instance-attribute
Default serialization (auto, raw, pickle, json)
uri: str
instance-attribute
Store base uri