Get¶
obspec.Get ¶
Bases: Protocol
get ¶
get(path: str, *, options: GetOptions | None = None) -> GetResult
Return the bytes that are stored at the specified location.
Parameters:
-
path
(str
) –The path within the store to retrieve.
-
options
(GetOptions | None
, default:None
) –options for accessing the file. Defaults to None.
Returns:
-
GetResult
–GetResult
obspec.GetAsync ¶
Bases: Protocol
get_async
async
¶
get_async(path: str, *, options: GetOptions | None = None) -> GetResultAsync
Call get
asynchronously.
Refer to the documentation for Get.
obspec.GetRange ¶
Bases: Protocol
get_range ¶
Return the bytes stored at the specified location in the given byte range.
If the given range is zero-length or starts after the end of the object, an error will be returned. Additionally, if the range ends after the end of the object, the entire remainder of the object will be returned. Otherwise, the exact requested range will be returned.
Parameters:
-
path
(str
) –The path within the store to retrieve.
Other Parameters:
-
start
(int
) –The start of the byte range.
-
end
(int | None
) –The end of the byte range (exclusive). Either
end
orlength
must be non-None. -
length
(int | None
) –The number of bytes of the byte range. Either
end
orlength
must be non-None.
Returns:
-
Buffer
–A
Buffer
object implementing the Python buffer protocol.
obspec.GetRangeAsync ¶
obspec.GetRanges ¶
Bases: Protocol
get_ranges ¶
get_ranges(
path: str,
*,
starts: Sequence[int],
ends: Sequence[int] | None = None,
lengths: Sequence[int] | None = None,
) -> Sequence[Buffer]
Return the bytes stored at the specified location in the given byte ranges.
The choice of how to implement multiple range requests is implementation specific.
Parameters:
-
path
(str
) –The path within the store to retrieve.
Other Parameters:
-
starts
(Sequence[int]
) –A sequence of
int
where each offset starts. -
ends
(Sequence[int] | None
) –A sequence of
int
where each offset ends (exclusive). Eitherends
orlengths
must be non-None. -
lengths
(Sequence[int] | None
) –A sequence of
int
with the number of bytes of each byte range. Eitherends
orlengths
must be non-None.
Returns:
obspec.GetRangesAsync ¶
obspec.GetOptions ¶
Bases: TypedDict
Options for a get request.
All options are optional.
if_match
instance-attribute
¶
if_match: str | None
Request will succeed if the ObjectMeta::e_tag
matches.
See datatracker.ietf.org/doc/html/rfc9110#name-if-match
Examples:
If-Match: "xyzzy"
If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-Match: *
if_modified_since
instance-attribute
¶
if_modified_since: datetime | None
Request will succeed if the object has not been modified since.
Some stores, such as S3, will only return NotModified
for exact
timestamp matches, instead of for any timestamp greater than or equal.
if_none_match
instance-attribute
¶
if_none_match: str | None
Request will succeed if the ObjectMeta::e_tag
does not match.
See datatracker.ietf.org/doc/html/rfc9110#section-13.1.2
Examples:
If-None-Match: "xyzzy"
If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-None-Match: *
if_unmodified_since
instance-attribute
¶
if_unmodified_since: datetime | None
Request will succeed if the object has been modified since
range
instance-attribute
¶
range: tuple[int, int] | Sequence[int] | OffsetRange | SuffixRange
Request transfer of only the specified range of bytes.
The semantics of this attribute are:
-
(int, int)
: Request a specific range of bytes(start, end)
.If the given range is zero-length or starts after the end of the object, an error will be returned. Additionally, if the range ends after the end of the object, the entire remainder of the object will be returned. Otherwise, the exact requested range will be returned.
The
end
offset is exclusive. -
{"offset": int}
: Request all bytes starting from a given byte offset.This is equivalent to
bytes={int}-
as an HTTP header. -
{"suffix": int}
: Request the lastint
bytes. Note that here,int
is the size of the request, not the byte offset. This is equivalent tobytes=-{int}
as an HTTP header.
obspec.GetResult ¶
Bases: Iterable[Buffer]
, Protocol
Result for a get request.
You can materialize the entire buffer by calling the bytes
method or you can
stream the result by iterating over it .
Example:
from obspec import Get
def streaming_download(client: Get, path: str):
resp = client.get(path)
for buffer in resp:
print(len(buffer))
range
property
¶
The range of bytes returned by this request.
Note that this is (start, stop)
not (start, length)
.
obspec.GetResultAsync ¶
Bases: AsyncIterable[Buffer]
, Protocol
Result for an async get request.
You can materialize the entire buffer by calling the bytes_async
method or you can
stream the result by asynchronously iterating over it.
Example:
from obspec import GetAsync
async def streaming_download(obs: GetAsync, path: str):
resp = await client.get_async(path)
async for buffer in resp:
print(len(buffer))
range
property
¶
The range of bytes returned by this request.
Note that this is (start, stop)
not (start, length)
.