Bucket
reduct.Bucket
¶
A bucket of data in Reduct Storage
get_entry_list()
async
¶
Get list of entries with their stats
Returns:
Type | Description |
---|---|
List[EntryInfo]
|
List[EntryInfo] |
Raises:
Type | Description |
---|---|
ReductError
|
if there is an HTTP error |
get_full_info()
async
¶
Get full information about bucket (settings, statistics, entries)
get_settings()
async
¶
Get current bucket settings
Returns:
Name | Type | Description |
---|---|---|
BucketSettings |
BucketSettings
|
|
Raises:
Type | Description |
---|---|
ReductError
|
if there is an HTTP error |
info()
async
¶
Get statistics about bucket
Returns:
Name | Type | Description |
---|---|---|
BucketInfo |
BucketInfo
|
|
Raises:
Type | Description |
---|---|
ReductError
|
if there is an HTTP error |
query(entry_name, start=None, stop=None, ttl=None, **kwargs)
async
¶
Query data for a time interval
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_name |
str
|
name of entry in the bucket |
required |
start |
Optional[int]
|
the beginning of the time interval |
None
|
stop |
Optional[int]
|
the end of the time interval |
None
|
ttl |
Optional[int]
|
Time To Live of the request in seconds |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
include |
dict
|
query records which have all labels from this dict |
exclude |
dict
|
query records which doesn't have all labels from this |
head |
bool
|
if True: get only the header of a recod with metadata |
limit |
int
|
limit the number of records |
Returns:
Type | Description |
---|---|
AsyncIterator[Record]
|
AsyncIterator[Record]: iterator to the records |
Examples:
>>> async for record in bucket.query("entry-1", stop=time.time_ns() / 1000):
>>> data: bytes = record.read_all()
>>> # or
>>> async for chunk in record.read(n=1024):
>>> print(chunk)
read(entry_name, timestamp=None, head=False)
async
¶
Read a record from entry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_name |
str
|
name of entry in the bucket |
required |
timestamp |
Optional[int]
|
UNIX timestamp in microseconds - if None: get the latest record |
None
|
head |
bool
|
if True: get only the header of a recod with metadata |
False
|
Returns:
Type | Description |
---|---|
Record
|
async context with a record |
Raises:
Type | Description |
---|---|
ReductError
|
if there is an HTTP error |
Examples:
>>> async def reader():
>>> async with bucket.read("entry", timestamp=123456789) as record:
>>> data = await record.read_all()
remove()
async
¶
remove_entry(entry_name)
async
¶
Remove entry from bucket
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_name |
str
|
name of entry |
required |
Raises:
Type | Description |
---|---|
ReductError
|
if there is an HTTP error |
set_settings(settings)
async
¶
Update bucket settings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings |
BucketSettings
|
new settings |
required |
Raises:
Type | Description |
---|---|
ReductError
|
if there is an HTTP error |
subscribe(entry_name, start=None, poll_interval=1.0, **kwargs)
async
¶
Query records from the start timestamp and wait for new records
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_name |
str
|
name of entry in the bucket |
required |
start |
Optional[int]
|
the beginning timestamp to read records |
None
|
poll_interval |
inteval to ask new records in seconds |
1.0
|
Other Parameters:
Name | Type | Description |
---|---|---|
include |
dict
|
query records which have all labels from this dict |
exclude |
dict
|
query records which doesn't have all labels from this dict |
head |
bool
|
if True: get only the header of a recod with metadata |
Returns:
Type | Description |
---|---|
AsyncIterator[Record]
|
AsyncIterator[Record]: iterator to the records |
Examples:
>>> async for record in bucket.subscribes("entry-1"):
>>> data: bytes = record.read_all()
>>> # or
>>> async for chunk in record.read(n=1024):
>>> print(chunk)
write(entry_name, data, timestamp=None, content_length=None, **kwargs)
async
¶
Write a record to entry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_name |
str
|
name of entry in the bucket |
required |
data |
Union[bytes, AsyncIterator[bytes]]
|
bytes to write or async iterator |
required |
timestamp |
Optional[int]
|
UNIX time stamp in microseconds. Current time if it's None |
None
|
content_length |
Optional[int]
|
content size in bytes, needed only when the data is an iterator |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
labels |
dict
|
labels as key-values |
content_type |
str
|
content type of data |
Raises:
Type | Description |
---|---|
ReductError
|
if there is an HTTP error |
Examples:
>>> await bucket.write("entry-1", b"some_data", timestamp=19231023101)
>>>
>>> # You can write data chunk-wise using an asynchronous iterator and the
>>> # size of the content:
>>>
>>> async def sender():
>>> for chunk in [b"part1", b"part2", b"part3"]:
>>> yield chunk
>>> await bucket.write("entry-1", sender(), content_length=15)