# Deduplicate & Merge Apify Datasets: remove duplicate items (`bosco_labs/dataset-dedup`) Actor

Deduplicate and merge one or more Apify datasets (or a pasted JSON array): removes duplicate items by any fields (dot paths allowed) or by the whole item, keeping the first or last occurrence. Streams millions of items with constant memory. Use to clean repeated scraper runs before export.

- **URL**: https://apify.com/bosco_labs/dataset-dedup.md
- **Developed by:** [Bosco Labs](https://apify.com/bosco_labs) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.15 / 1,000 unique items

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Deduplicate & Merge Apify Datasets: remove duplicate items

**Deduplicate and merge one or more Apify datasets into one**, removing duplicate items by any
fields you choose (for example `url`, `email` or `address.city`), or by the whole item. Built for people
who run the same scraper many times, or several scrapers, and need one clean list. It streams
the data, so millions of items run with constant memory.

**Pricing (pay per event):** $0.00015 per unique item written ($0.15 per 1,000). Duplicates
are free, reading is free, there is no start fee, and the run stops at your max charge limit.

### Input

```json
{
  "datasetIds": ["aBcD1234efGH5678i", "jKlM9012noPQ3456r"],
  "fields": ["url"],
  "keep": "first",
  "outputFields": ["url", "title", "price"]
}
```

| Field | Meaning |
|---|---|
| `datasetIds` | Datasets to merge, in this order |
| `items` | Or paste a JSON array of items directly (processed first) |
| `fields` | Two items are duplicates when all these fields are equal. Dot paths work: `address.city`, `emails.0`. Empty = compare whole items |
| `keep` | `first` (default) keeps the first occurrence; `last` keeps the last one |
| `outputFields` | Keep only these top-level fields in the output. Empty = all fields |

### Output

The unique items, unchanged, in input order (dataset 1 first, then dataset 2, ...). With the
input above and these two datasets:

```json
[{"url": "https://a.com/1", "title": "A", "price": 10},
 {"url": "https://a.com/2", "title": "B", "price": 12}]
[{"url": "https://a.com/1", "title": "A", "price": 9},
 {"url": "https://a.com/3", "title": "C", "price": 7}]
```

the output dataset is:

```json
[{"url": "https://a.com/1", "title": "A", "price": 10},
 {"url": "https://a.com/2", "title": "B", "price": 12},
 {"url": "https://a.com/3", "title": "C", "price": 7}]
```

With `"keep": "last"` the first row would be the one with `"price": 9`, at the position of
its last occurrence. The log ends with the counts: `read=4 duplicates=1 written=3`.

### Use cases

- **Daily scrapes without repeats:** merge today's run with earlier runs and keep only new
  URLs, products or listings.
- **Lead lists:** combine several scrapers (Maps, websites, directories) and dedupe on
  `email` or `phone`.
- **Latest price per product:** dedupe on `sku` with `keep: last`.
- **Before exporting:** clean a dataset before it goes to Sheets, a CRM or a warehouse.

### Use with AI agents (MCP)

Agents can call this Actor as a tool through the
[Apify MCP server](https://github.com/apify/apify-mcp-server). Add this server URL to your MCP
client (Claude, Cursor, VS Code, ...):

```text
https://mcp.apify.com?tools=bosco_labs/dataset-dedup
```

It loads this Actor as a tool, plus the tools that read its results (`get-actor-run`,
`get-dataset-items`). The hosted server signs you in with OAuth, or accepts your Apify token as
`Authorization: Bearer <APIFY_TOKEN>`. On the default server (`https://mcp.apify.com`), agents
can also find this Actor with `search-actors` and run it with `call-actor`.

Example prompts this Actor answers:

- *"Merge the results of my last three Google Maps runs and remove duplicate places by placeId."*
- *"Deduplicate this list of leads by email and keep only name, email and website."*
- *"Keep only the latest price per SKU from these two product datasets."*

For the first one, the agent passes:

```json
{"datasetIds": ["<dataset ID 1>", "<dataset ID 2>", "<dataset ID 3>"], "fields": ["placeId"]}
```

**Output for agents:** the unique items, unchanged and in input order, in the run's default
dataset. The Actor adds no fields of its own (no `schema_version` or source link), since the
items are your data; the run log ends with `read`, `duplicates` and `written` counts.

**Cost:** $0.00015 per unique item written (duplicates are free), billed to the Apify account the MCP server is signed in with.

### FAQ

**How big can the datasets be?** For every distinct key the Actor keeps a 16-byte hash in
memory, never the items. 10 million distinct keys need roughly 1-2 GB, so most runs fit in the
default memory.

**Is `keep: last` slower?** It reads the input datasets twice (once to find the last
occurrence of each key, once to write), still without holding the items in memory.

**What about items that don't have the dedupe field?** They are always kept, never merged
with each other, and counted as `kept_without_key` in the log. A field that is `null` counts as
missing.

**Are `1` and `"1"` the same?** No. Values are compared exactly as stored (type included).
Whole-item comparison ignores the order of keys.

**Which datasets can it read?** Only the ones you pick in the input. The Actor runs with
limited permissions, so it can't see any other storage in your account.

**What if the run is restarted by the platform?** It starts over, skips the items it already
wrote, and doesn't charge them again.

# Actor input Schema

## `datasetIds` (type: `array`):

Apify dataset IDs to merge, in this order, e.g. \["aBcD1234efGH5678i"]: a run's defaultDatasetId (Storage tab). Optional if you pass `items`.

## `items` (type: `array`):

Items to deduplicate directly, as a JSON array of objects, e.g. \[{"url": "https://example.com/a"}]. Processed before the datasets. Handy for small lists and quick tests.

## `fields` (type: `array`):

Fields that form the duplicate key: items with equal values in all of them are duplicates. Dot paths work, e.g. \["url"] or \["address.city", "emails.0"]. Default \[] = compare whole items. Items that have none of these fields are always kept.

## `keep` (type: `string`):

"first" (default) keeps the first occurrence of each key; "last" keeps the last one and reads the datasets twice.

## `outputFields` (type: `array`):

Top-level fields to keep in the output, e.g. \["url", "title"]. Empty = keep every field.

## Actor input object example

```json
{
  "items": [
    {
      "url": "https://example.com/a",
      "name": "A"
    },
    {
      "url": "https://example.com/b",
      "name": "B"
    },
    {
      "url": "https://example.com/a",
      "name": "A (duplicate)"
    }
  ],
  "fields": [
    "url"
  ],
  "keep": "first"
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "items": [
        {
            "url": "https://example.com/a",
            "name": "A"
        },
        {
            "url": "https://example.com/b",
            "name": "B"
        },
        {
            "url": "https://example.com/a",
            "name": "A (duplicate)"
        }
    ],
    "fields": [
        "url"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("bosco_labs/dataset-dedup").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "items": [
        {
            "url": "https://example.com/a",
            "name": "A",
        },
        {
            "url": "https://example.com/b",
            "name": "B",
        },
        {
            "url": "https://example.com/a",
            "name": "A (duplicate)",
        },
    ],
    "fields": ["url"],
}

# Run the Actor and wait for it to finish
run = client.actor("bosco_labs/dataset-dedup").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "items": [
    {
      "url": "https://example.com/a",
      "name": "A"
    },
    {
      "url": "https://example.com/b",
      "name": "B"
    },
    {
      "url": "https://example.com/a",
      "name": "A (duplicate)"
    }
  ],
  "fields": [
    "url"
  ]
}' |
apify call bosco_labs/dataset-dedup --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bosco_labs/dataset-dedup"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/0ZZ02yq35zUnZbwH5/builds/f8MSe8h4GhUQJOjzJ/openapi.json
