here.platform.api.stream module

here.platform.api.stream module

This module contains classes to implement streaming requests with retries.

class here.platform.api.stream.ChunkedGet(api: BaseApi, response: Response, chunk_size: int)
Bases: RawIOBase, Iterator[bytes]

Custom iterator for iterating content from a GET request that allows retries on error by using the Range HTTP header to restart where it left off.

This may also be used as a file-like stream.

close()

Closes the stream and releases any resources.

read(size: int = -1) bytes

Reads bytes from the stream.

Parameters:
size – the requested number of bytes to read. Fewer bytes may be read if it would require multiple requests. If negative, all remaining data will be read as if readall() was called.

Returns:
the read bytes.

readable() bool

Denotes to the RawIO API that this stream is readable.

Returns:
True to indicate the stream is readable.

readall() bytes

Reads all remaining bytes from the stream.

Returns:
the read bytes.

readinto(b) int

Reads bytes into a pre-allocated buffer.

Parameters:
b – a buffer-like object to read into.

Returns:
the number of bytes read.

seek(offset: int, whence=0) int

Seeks in the stream. Only seeking forward is supported.

Parameters:

  • offset – the offset to seek by.

  • whence – the position offset is relative to.

Returns:
the new position in the stream.

Raises:
OSError – if seeking backward.

seekable() bool

Allow seeking to skip forward, allowing for buffered reading within json_stream.

Returns:
True to state that this is seekable.

tell() int

Tells the current position in the stream.

Returns:
the current position in bytes.

here.platform.api.stream.find_list_of_objects(parent: dict | StreamingJSONObject, field: str) list[dict] | StreamingJSONList

Finds a list of objects to iterate over from either a fully loaded JSON dict or streaming JSON. When performing streaming parsing, this will persist the individual objects so lookups can succeed regardless of the order they are present in the JSON document. This assumes a potentially enormous list of small objects.

Parameters:

  • parent – the parent object to look in.

  • field – the field to look up.

Returns:
the list of objects. If field is not present, an empty list will be returned.

here.platform.api.stream.stream_json_response(api: BaseApi, response: Response, chunk_size: int) StreamingJSONObject

Streams loading a JSON response to avoid keeping the full document in memory.

Parameters:

  • api – the API the request was made with.

  • response – the response to the request.

  • chunk_size – the desired amount of data to request at a time.

Returns:
an object to access the streamed JSON data.