streamable

streamable is a callable class that can be used as a decorator on functions returning an asynchronous iterator. It is applied on functions such as new() and submissions().

Streamable functions can be called by adding .stream(), for example reddit.subreddits.new.stream().

class apraw.models.streamable(func: Optional[Union[Callable[[Any, int, Any], Union[Awaitable[Union[AsyncIterator[apraw.models.helpers.apraw_base.aPRAWBase], Iterator[apraw.models.helpers.apraw_base.aPRAWBase]]], AsyncIterator[apraw.models.helpers.apraw_base.aPRAWBase], Iterator[apraw.models.helpers.apraw_base.aPRAWBase]]], AsyncGenerator[apraw.models.helpers.apraw_base.aPRAWBase, None], Generator[apraw.models.helpers.apraw_base.aPRAWBase, None, None]]] = None, max_wait: int = 16, attribute_name: str = 'fullname')

A decorator to add the stream() extension to functions returning (async) iterables or (async) generators.

Parameters
  • func (SYNC_OR_ASYNC_ITERABLE) – The function returning an (async) iterable or (async) generator to be decorated.

  • max_wait (int) – The maximum amount of time to wait in between requests that don’t return new data.

  • attribute_name (str) – The attribute to use as a unique identifier for items returned by the decorated function.

Returns

proxy – A proxy descriptor that returns Streamable once it’s accessed to enable per-instance use for bound methods and regular functions.

Return type

ProxyStreamable

class apraw.models.Streamable(func: Union[Callable[[Any, int, Any], Union[Awaitable[Union[AsyncIterator[apraw.models.helpers.apraw_base.aPRAWBase], Iterator[apraw.models.helpers.apraw_base.aPRAWBase]]], AsyncIterator[apraw.models.helpers.apraw_base.aPRAWBase], Iterator[apraw.models.helpers.apraw_base.aPRAWBase]]], AsyncGenerator[apraw.models.helpers.apraw_base.aPRAWBase, None], Generator[apraw.models.helpers.apraw_base.aPRAWBase, None, None]], max_wait: int = 16, attribute_name: str = 'fullname', instance: Optional[Any] = None)

A decorator to make functions returning a generator streamable.

max_wait: int

The maximum amount of seconds to wait before repolling the function.

attribute_name: str

The attribute name to use as a unique identifier for returned objects.

__call__(*args, **kwargs)

Make streamable callable to return result of decorated function.

stream(skip_existing: bool = False, *args, **kwargs)

Call the stream method on the decorated function.

Parameters
  • skip_existing (bool) – Whether items found before the function call should be returned as well.

  • kwargs (**Dict) – kwargs to be passed on to the function.

Yields

item (aPRAWBase) – The item retrieved by the function in chronological order.