Skip to content

HttpStream

iotoolz.HttpStream is a stream interface implemented with the popular requests package.

iotoolz.http.HttpStream

HttpStream is the stream interface to http/https resources using "requests".

supported_schemas: Set[str]

Methods

exists(self)

Whether the http resource exists.

iter_dir_(self)

This method does nothing.

mkdir(self, mode=511, parents=False, exist_ok=False)

This method does nothing as the actual HTTP call will handle any folder creation as part of the request.

read_to_iterable_(self, uri, chunk_size, fileobj, **kwargs)

Implements a http GET request using "requests" with stream flag always set.

Parameters:

Name Type Description Default
uri str

http or https endpoint to retrieve the data.

required
chunk_size int

size for each bytes chunk (provided in the Stream constructor).

required
fileobj IO[bytes]

file-like object of the stream buffer.

required
**kwargs

keyword arguments that will be passed to the "requests.get" method.

{}

Returns:

Type Description
Tuple[Iterable[bytes], iotoolz._abc.StreamInfo]

Tuple[Iterable[bytes], StreamInfo]: tuple of the bytes iterable and StreamInfo.

stats_(self)

Retrieve the StreamInfo.

Delete and remove the resource.

write_from_fileobj_(self, uri, fileobj, size, **kwargs)

Implements a http PUT or POST request using the "requests" lib.

This implements takes in an additional "use_post" flag to indicate whether the http method should be PUT (default) or POST.

Parameters:

Name Type Description Default
uri str

http/https endpoint to PUT/POST the data.

required
fileobj IO[bytes]

file-like object of the current data in buffer.

required
size int

size of the data in the file-like object.

required
**kwargs

additional keyword arguments to pass to the "requests.put" or "requests.post" method.

{}

Returns:

Type Description
StreamInfo

StreamInfo: [description]


Last update: October 27, 2020