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
ProgressTask
A labelled bar on a SyncProgressBar.
Use it as a context manager to have it disappear when its work is done:
Example
Source code in anystore/io/progress.py
advance(items=1, size=None)
Advance the task, optionally accounting transferred bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
int | None
|
Number of items completed (default: 1) |
1
|
size
|
int | None
|
Bytes transferred for them, added to this task's throughput and to the overall throughput of the bar |
None
|
Source code in anystore/io/progress.py
remove()
SmartHandler
Source code in anystore/io/handler.py
SyncProgressBar
A live display of one or more bars, with byte throughput.
For a single bar, describe it up front and advance the display itself:
Example
For concurrent work, add a bar per unit of it with
task – they may be advanced
from any thread, and all of them live in this one display, as wrapping each
bar in a display of its own would leave all but the first invisible (rich
only renders the outermost live display):
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str | None
|
Label for the display's own bar – leave it out for the multi-task case, where each task brings its own |
None
|
total
|
int | None
|
Number of items for that bar, if known |
None
|
console
|
Console | None
|
Console to render on (default: a new one on the current
|
None
|
columns
|
Sequence[str | ProgressColumn] | None
|
Custom rich progress columns |
None
|
transient
|
bool | None
|
Remove the whole display when it's done (default: yes) |
True
|
route_logging
|
bool | None
|
Print log output through the same console while the display is running (default: yes) |
True
|
disable
|
bool | None
|
Render nothing at all, e.g. for a |
False
|
window
|
int | None
|
Seconds to average throughput rates over |
DEFAULT_WINDOW
|
Source code in anystore/io/progress.py
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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
default_task
property
The display's own bar, for the single-bar case
progress
property
The underlying rich Progress, once the display is started
advance(items=1, size=None)
Advance the display's own bar, optionally accounting transferred bytes.
Only for the single-bar case – with several tasks, advance those.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
int | None
|
Number of items completed (default: 1) |
1
|
size
|
int | None
|
Bytes transferred for them |
None
|
Source code in anystore/io/progress.py
start()
Start rendering (and, unless turned off, routing log output)
Source code in anystore/io/progress.py
stop()
task(description, total=None, throughput=None)
Add a labelled bar to the display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str
|
The label, e.g. the key prefix being worked on |
required |
total
|
int | None
|
Number of items, if known – an unknown total pulses instead of filling up |
None
|
throughput
|
Throughput | None
|
Byte counter to display, pass the bar's own
|
None
|
Returns:
| Type | Description |
|---|---|
ProgressTask
|
The task handle, removable and usable as a context manager |
Source code in anystore/io/progress.py
Throughput
Thread-safe byte counter exposing a rolling transfer rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int | None
|
Seconds to average the rate over |
DEFAULT_WINDOW
|
Source code in anystore/io/progress.py
rate
property
Bytes per second over the last window seconds.
ThroughputColumn
Bases: ProgressColumn
Renders the byte throughput of a task's Throughput field.
The item count says how far along a task is; this says how fast bytes are actually moving.
Source code in anystore/io/progress.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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
close()
open()
The open target, created on first ask.
A csv whose header is known up front writes it here, so a writer that never sees a row still leaves a complete – if empty – table instead of a zero-byte file.
Source code in anystore/io/write.py
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
logging_through(console)
Route log output through a rich console for the duration of the block, so log lines don't cut into whatever that console is rendering.
anystore's log handlers resolve sys.stderr on every emit, so swapping it
is enough to catch them – as well as warnings and any other library writing
to stderr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Console
|
The console to print through |
required |
Source code in anystore/io/progress.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