anystore.io
Generic io helpers
anystore
is built on top of
fsspec
and
provides an easy wrapper for reading and writing content from and to arbitrary
locations using the io
command:
Command-line usage
Python usage
logged_items(items, action, chunk_size=10000, uri=None, item_name=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 |
uri
|
Uri | None
|
string or path-like key uri (only for logging purpose) |
None
|
chunk_size
|
int | None
|
Log on every chunk_size |
10000
|
item_name
|
str | None
|
Name of item |
None
|
Yields:
Type | Description |
---|---|
T
|
The input items |
Source code in anystore/io.py
smart_open(uri, mode=DEFAULT_MODE, **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
|
**kwargs
|
Any
|
pass through storage-specific options |
{}
|
Yields:
Type | Description |
---|---|
IO
|
A generic file-handler like context object |
Source code in anystore/io.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.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.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.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.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 |
{}
|