ApifyClient.Datasets (apify_client v1.0.0)

Copy Markdown View Source

Dataset items: read, stream and push them.

{:ok, items} = ApifyClient.Datasets.list_items(dataset_id, limit: 100, clean: true)

ApifyClient.Datasets.stream_items(dataset_id)
|> Stream.map(&Map.fetch!(&1, "url"))
|> Enum.to_list()

Items are returned as decoded JSON (maps with string keys), as the Actor stored them.

Functions take the connection options described in ApifyClient.Client (:token, :config, ...) next to their own. For everything else about datasets, see ApifyClient.API.Datasets and ApifyClient.API.Datasets.Items.

Summary

Functions

Gets one page of items.

Adds items to a dataset: one item (a map) or a list of them.

Streams all items, fetching them page by page as the stream is consumed.

Functions

list_items(dataset_id, opts \\ [])

@spec list_items(String.t(), keyword()) ::
  {:ok, [map()] | binary()} | {:error, ApifyClient.Error.t()}

Gets one page of items.

With the default JSON format the items come back as a list of maps. With another :format ("csv", "xlsx", "jsonl", "html", "xml", "rss") the body comes back as a binary.

Options

The options of ApifyClient.API.Datasets.Items.list/2, among them:

  • :offset, :limit - the page (the API returns at most 1000 items per page)
  • :clean - leave out empty and hidden items and fields (skip_empty and skip_hidden together)
  • :fields, :omit - fields to include or leave out, as a list
  • :desc - newest items first
  • :format - see above

push_items(dataset_id, items, opts \\ [])

@spec push_items(String.t(), map() | [map()], keyword()) ::
  :ok | {:error, ApifyClient.Error.t()}

Adds items to a dataset: one item (a map) or a list of them.

Items are sent as JSON with their keys as given.

stream_items(dataset_id, opts \\ [])

@spec stream_items(String.t(), keyword()) :: Enumerable.t()

Streams all items, fetching them page by page as the stream is consumed.

Raises ApifyClient.Error if a page can't be fetched.

Options

The options of list_items/2 (always in JSON format), where :offset and :limit apply to the whole stream, plus:

  • :page_size - items per request (default and maximum: 1000)