aws
Classes:
-
S3Storage–Storage for S3 data.
StreamBufferType
module-attribute
StreamBufferType = Callable[
[], AbstractContextManager[IO[bytes]]
]
A function that returns a context manager for a stream buffer.
S3Pointer
S3Router
S3Storage
S3Storage(
*,
s3_client: S3Client,
s3_router: S3Router | None,
max_writers: int | None = None,
max_readers: int | None = None,
stream_writer_min_part_size: int = _5MB,
stream_writer_buffer_type: StreamBufferType = lambda: SpooledTemporaryFile(
max_size=_5MB
),
stream_reader_max_part_size: int = _5MB
)
Bases: Storage['S3Pointer']
Storage for S3 data.
Parameters:
-
(s3_clientS3Client) –The S3 client to use for storage operations.
-
(s3_routerS3Router | None) –The S3 router to use for mapping digests to S3 pointers.
-
(max_writersint | None, default:None) –The maximum number of concurrent writes to S3.
-
(max_readersint | None, default:None) –The maximum number of concurrent reads from S3.
-
(stream_writer_min_part_sizeint, default:_5MB) –The minimum part size written to S3 while streaming.
-
(stream_writer_buffer_typeStreamBufferType, default:lambda: SpooledTemporaryFile(max_size=_5MB)) –The buffer type to use for streaming writes.
-
(stream_reader_max_part_sizeint, default:_5MB) –The maximum part size read from S3 while streaming.
Methods:
-
deserialize_config–Deserialize the configuration from a JSON string.
-
read_data–Load the value from the given location.
-
read_data_stream–Load the stream from the given location.
-
serialize_config–Serialize the configuration to a JSON string.
-
write_data–Save the given value.
-
write_data_stream–Save the given data stream.
deserialize_config
deserialize_config(config: str) -> C
Deserialize the configuration from a JSON string.
read_data_stream
async
read_data_stream(
pointer: S3Pointer,
) -> AsyncGenerator[bytes]
Load the stream from the given location.
write_data
async
Save the given value.
write_data_stream
async
write_data_stream(
data_stream: AsyncIterable[bytes],
get_digest: GetStreamDigest,
tags: TagMap,
) -> S3Pointer
Save the given data stream.
This works by first saving the stream to a temporary key becuase the content hash is not known until the stream is fully read. The data has been written to the temporary key it's copied to its final location based on the content hash.