Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix examples in docstrings #54

Merged
merged 3 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Client.get_bucket` now uses `GET` instead of `HEAD` in order to be able to return a meaningful error to the user, [PR-51](https://github.com/reduct-storage/reduct-py/pull/51)
- `Client` class now catches parsing errors raised by incorrect server configurations or missing servers, [PR-52](https://github.com/reduct-storage/reduct-py/pull/52)

### Fixed:

- Fix examples in docstrings, [PR-54](https://github.com/reduct-storage/reduct-py/pull/54)

## [v1.0.0] - 2022-10-18

### Added:
Expand Down
40 changes: 22 additions & 18 deletions pkg/reduct/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ async def read(
) -> AsyncIterator[Record]:
"""
Read a record from entry

>>> async def reader():
>>> async with bucket.read("entry", timestamp=123456789) as record:
>>> data = await record.read_all()
Args:
entry_name: name of entry in the bucket
timestamp: UNIX timestamp in microseconds - if None: get the latest record
Returns:
async context, which generates Records
Raises:
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()
"""
params = {"ts": timestamp} if timestamp else None
async with self._http.request(
Expand All @@ -209,15 +209,6 @@ async def write(
"""
Write a record to entry

>>> 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)
Args:
entry_name: name of entry in the bucket
data: bytes to write or async iterator
Expand All @@ -227,6 +218,17 @@ async def write(
Raises:
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)

"""
params = {"ts": timestamp if timestamp else time.time_ns() / 1000}

Expand All @@ -248,11 +250,6 @@ async def query(
"""
Query data for a time interval

>>> 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)
Args:
entry_name: name of entry in the bucket
start: the beginning of the time interval
Expand All @@ -261,6 +258,13 @@ async def query(

Returns:
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)
"""
params = {}
if start:
Expand Down
7 changes: 5 additions & 2 deletions pkg/reduct/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ async def get_bucket(self, name: str) -> Bucket:
return Bucket(name, self._http)

async def create_bucket(
self, name: str, settings: Optional[BucketSettings] = None, exist_ok=False
self,
name: str,
settings: Optional[BucketSettings] = None,
exist_ok: bool = False,
) -> Bucket:
"""
Create a new bucket
Expand All @@ -114,7 +117,7 @@ async def create_bucket(
settings: settings for the bucket If None, the server
default settings is used.
exist_ok: the client raises no exception if the bucket
already exists and returns it
already exists and returns it
Returns:
Bucket: created bucket
Raises:
Expand Down