ApifyClient.Pagination (apify_client v1.0.0)

Copy Markdown View Source

Streams every item of a paginated list endpoint.

Most list endpoints page with offset and limit and return the items in an items field (ApifyClient.Schemas.ListOfRuns, ApifyClient.Schemas.ListOfDatasets, ...). stream/2 turns any of them into a lazy stream that fetches the next page when the stream needs it:

# All runs of an Actor, newest first
ApifyClient.Pagination.stream(&ApifyClient.API.Actors.Runs.list("apify~web-scraper", &1), desc: true)
|> Enum.take(20)

# All named datasets
ApifyClient.Pagination.stream(&ApifyClient.API.Datasets.list/1, config: config)
|> Enum.map(& &1.name)

For dataset items use ApifyClient.Datasets.stream_items/2, and for key-value store keys, which page by key, ApifyClient.KeyValueStores.stream_keys/2.

Some endpoints ignore offset for some options: the Store (ApifyClient.API.Store.list/1) does when search is given. The stream raises ApifyClient.Error when a page comes back from another offset than requested, instead of repeating the first page forever.

Summary

Functions

Returns a stream of the items of all pages.

Functions

stream(list, opts \\ [])

@spec stream(
  (keyword() -> {:ok, term()} | {:error, ApifyClient.Error.t()}),
  keyword()
) ::
  Enumerable.t()

Returns a stream of the items of all pages.

list is called with a keyword list of options for each page: the options given here (connection options, filters such as :desc or :status) with :offset and :limit set for the page. It must return {:ok, page}, where page has an items field (or is the list of items itself), or {:error, %ApifyClient.Error{}}, which the stream raises.

Options

  • :offset - number of items to skip at the start (default: 0)
  • :limit - maximum number of items in the whole stream (default: all)
  • :page_size - items per request (default: 1000)

Other options are passed on to list.