anystore.io
IOFormat
ModelWriter
Bases: Writer
A generic writer for pydantic objects to any out uri, either json or csv
Source code in anystore/io/write.py
SmartHandler
Source code in anystore/io/handler.py
Writer
A generic writer for python dict objects to any out uri, either json or csv
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to write to, |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_WRITE_MODE
|
output_format
|
Formats | None
|
csv or json (default: json) |
'json'
|
fieldnames
|
list[str] | None
|
csv header, inferred from the first row when omitted |
None
|
clean
|
bool | None
|
Apply clean_dict |
False
|
compression
|
CompressKind | str | None
|
Codec to compress the output with ("gz", "bz2", "xz", "zst", "lz4") |
None
|
lazy
|
bool | None
|
Defer creating the target to the first |
False
|
**kwargs
|
pass through storage-specific options |
{}
|
Source code in anystore/io/write.py
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 | |
close()
logged_items(items, action, chunk_size=10000, item_name=None, logger=None, total=None, **log_kwargs)
Log process of iterating items for io operations.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterable[T]
|
Sequence of any items |
required |
action
|
str
|
Action name to log |
required |
chunk_size
|
int | None
|
Log on every chunk_size |
10000
|
item_name
|
str | None
|
Name of item |
None
|
logger
|
Logger | BoundLogger | None
|
Specific logger to use |
None
|
Yields:
| Type | Description |
|---|---|
T
|
The input items |
Source code in anystore/io/logging.py
open_virtual(uri, algorithm=None, **kwargs)
Wrapper for UriResource.local_open
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
'TUri'
|
string or path-like key uri to open |
required |
algorithm
|
str | None
|
Checksum algorithm from |
None
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Source code in anystore/io/read.py
smart_open(uri, mode=DEFAULT_MODE, compression=None, **kwargs)
IO context similar to pythons built-in open().
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_MODE
|
compression
|
CompressKind | str | None
|
Codec to (de-)compress the stream with ("gz", "bz2", "xz", "zst", "lz4") |
None
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Yields:
| Type | Description |
|---|---|
IO[Any]
|
A generic file-handler like context object |
Source code in anystore/io/handler.py
smart_read(uri, mode=DEFAULT_MODE, **kwargs)
Return content for a given file-like key directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_MODE
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Returns:
| Type | Description |
|---|---|
AnyStr
|
|
Source code in anystore/io/read.py
smart_stream(uri, mode=DEFAULT_MODE, **kwargs)
Stream content line by line.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_MODE
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Yields:
| Type | Description |
|---|---|
AnyStr
|
A generator of |
Source code in anystore/io/read.py
smart_stream_csv(uri, **kwargs)
Stream csv as python objects.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Yields:
| Type | Description |
|---|---|
SDictGenerator
|
A generator of |
Source code in anystore/io/read.py
smart_stream_csv_models(uri, model, **kwargs)
Stream csv as pydantic objects
Source code in anystore/io/read.py
smart_stream_data(uri, input_format, **kwargs)
Stream data objects loaded as dict from json or csv sources
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
input_format
|
str
|
csv or json |
required |
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Yields:
| Type | Description |
|---|---|
SDictGenerator
|
A generator of |
Source code in anystore/io/read.py
smart_stream_json(uri, mode=DEFAULT_MODE, **kwargs)
Stream line-based json as python objects.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_MODE
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Yields:
| Type | Description |
|---|---|
SDictGenerator
|
A generator of |
Source code in anystore/io/read.py
smart_stream_json_models(uri, model, **kwargs)
Stream json as pydantic objects
Source code in anystore/io/read.py
smart_stream_models(uri, model, input_format, **kwargs)
Stream json as pydantic objects
Source code in anystore/io/read.py
smart_write(uri, content, mode=DEFAULT_WRITE_MODE, **kwargs)
Write content to a given file-like key directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
content
|
bytes | str
|
|
required |
mode
|
str | None
|
open mode, default |
DEFAULT_WRITE_MODE
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Source code in anystore/io/write.py
smart_write_csv(uri, items, mode=DEFAULT_WRITE_MODE, **kwargs)
Write python data to csv
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
items
|
Iterable[SDict]
|
Iterable of dictionaries |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_WRITE_MODE
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Source code in anystore/io/write.py
smart_write_data(uri, items, mode=DEFAULT_WRITE_MODE, output_format='json', **kwargs)
Write python data to json or csv
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
items
|
Iterable[SDict]
|
Iterable of dictionaries |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_WRITE_MODE
|
output_format
|
Formats | None
|
csv or json (default: json) |
'json'
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Source code in anystore/io/write.py
smart_write_json(uri, items, mode=DEFAULT_WRITE_MODE, **kwargs)
Write python data to json
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
items
|
Iterable[SDict]
|
Iterable of dictionaries |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_WRITE_MODE
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Source code in anystore/io/write.py
smart_write_model(uri, obj, mode=DEFAULT_WRITE_MODE, output_format='json', clean=False, **kwargs)
Write a single pydantic object to the target
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
obj
|
BaseModel
|
Pydantic object |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_WRITE_MODE
|
clean
|
bool | None
|
Apply clean_dict |
False
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Source code in anystore/io/write.py
smart_write_models(uri, objects, mode=DEFAULT_WRITE_MODE, output_format='json', clean=False, **kwargs)
Write pydantic objects to json lines or csv
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
string or path-like key uri to open, e.g. |
required |
objects
|
Iterable[BaseModel]
|
Iterable of pydantic objects |
required |
mode
|
str | None
|
open mode, default |
DEFAULT_WRITE_MODE
|
clean
|
bool | None
|
Apply clean_dict |
False
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Source code in anystore/io/write.py
stream_bytes(key, source, target, **kwargs)
Stream binary content for key from source to target store. Returns streamed bytes count