# Dataset Dedup, Merge & Diff – New and Changed Items (`stevenkramp/dataset-dedup-delta-merge`) Actor

Deduplicate and merge Apify datasets by key fields, or compare with a previous dataset and get only new, changed and removed items. No web requests, your data stays in your account.

- **URL**: https://apify.com/stevenkramp/dataset-dedup-delta-merge.md
- **Developed by:** [Steven Kramp](https://apify.com/stevenkramp) (community)
- **Categories:** Developer tools, Automation, AI
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.18 / 1,000 output items

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/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

## Dataset Dedup, Merge & Diff – New and Changed Items

A small utility for **Apify datasets**: remove duplicates across several runs, merge records that belong together, or compare today's dataset with yesterday's and keep **only what is new, changed or removed**.

**$0.25 per 1,000 output items.** No web requests, no proxy, no browser. Your data stays in your Apify account.

### Modes

| mode | result |
| --- | --- |
| `dedup` (default) | first item per key, in input order |
| `merge` | one item per key; later non-empty values overwrite, missing fields are filled |
| `diff_new` | items whose key is not in `previousDatasetId` |
| `diff_changes` | `new`, `changed` and `removed` items compared with `previousDatasetId` |

In the diff modes every row has the extra field `_diffStatus`. A `removed` row is the item from the previous dataset.

### Input

```json
{
  "datasetIds": ["YOUR_DATASET_ID", "ANOTHER_DATASET_ID"],
  "keyFields": ["url"],
  "mode": "diff_changes",
  "previousDatasetId": "YESTERDAYS_DATASET_ID",
  "stripUrlQuery": true,
  "ignoreFields": ["scrapedAt"]
}
```

| Field | Default | Meaning |
| --- | --- | --- |
| `keyFields` | required | fields that identify an item; dot paths such as `meta.id` work |
| `datasetIds` | – | 1–50 datasets, read in this order |
| `inlineItems` | – | JSON objects instead of datasets; ignored when `datasetIds` is set |
| `mode` | `dedup` | see above |
| `previousDatasetId` | – | required for the diff modes |
| `trimValues` | `true` | ignore leading and trailing spaces |
| `ignoreCase` | `false` | ignore upper and lower case in keys |
| `stripUrlQuery` | `false` | ignore query and fragment of URL keys |
| `ignoreFields` | `["scrapedAt"]` | fields that do not count as a change |
| `maxInputItems` | 200,000 | safety limit per side (up to 500,000) |

**Memory:** 256 MB is enough for `dedup` and `diff_new`. Use 512 MB for `diff_changes` with more than 300,000 previous items and for large `merge` runs; if the memory is too small for a merge, the run stops before saving anything.

Matching rules only affect the comparison. Output values are never rewritten. The numbers 5 and 5.0 and the text "5" are the same key.

### Output example (fictional, `diff_changes`)

```json
{"url": "https://example.com/a", "title": "New title", "price": 12, "_diffStatus": "changed"}
{"url": "https://example.com/c", "title": "Third", "price": 9, "_diffStatus": "new"}
{"url": "https://example.com/b", "title": "Second", "price": 7, "_diffStatus": "removed"}
```

The **SUMMARY** record in the key-value store has `inputCount`, `outputCount`, `duplicatesRemoved`, `newCount`, `changedCount`, `removedCount`, `unchangedCount`, `missingKeyCount`, `previousCount`, `truncated`, `removalsChecked` and `stoppedBy`. Counters that a mode does not compute are `null`.

### Honest failure instead of wrong results

The run fails and saves nothing when:

- no item has any of the key fields (usually a typo in `keyFields`),
- a dataset cannot be read,
- `diff_changes` gets an empty current input while the previous dataset has items (the source run probably failed),
- the previous dataset is larger than `maxInputItems`.

`removed` is only reported when the current input was read completely. Items without any key value are kept in `dedup` and `merge` and skipped in the diff modes (`missingKeyCount`). A run stopped by the timeout fails, because its output is incomplete.

### Pricing

Pay per event. FREE is an Apify subscription tier, not a promise of free events.

| Billing event | Unit | FREE | BRONZE | SILVER | GOLD |
|---|---|---:|---:|---:|---:|
| `apify-actor-start` | per run | $0.00005 | $0.00005 | $0.00005 | $0.00005 |
| `item` | per 1,000 events | $0.25 | $0.225 | $0.20 | $0.175 |

You pay for output rows, not for input rows. Platform usage is included. Check the [Pricing tab](https://apify.com/stevenkramp/dataset-dedup-delta-merge/pricing) for the current rates, other applicable charges and taxes.

### Chain it behind any Actor

Add this Actor as an integration after a scraper run and pass the run's default dataset as `datasetIds`. For daily monitoring, pass yesterday's dataset as `previousDatasetId`.

### Use with AI agents (MCP)

```
https://mcp.apify.com?tools=stevenkramp/dataset-dedup-delta-merge
```

Example: “Compare these two datasets by id and show me only the new and changed records.”

### FAQ

**Does it change my input datasets?** No. It reads them and writes to the run's own dataset.

**Something broken?** Open an issue in the Issues tab.

# Actor input Schema

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

1-50 datasets of your account, read in this order. Leave empty to use Inline items.

## `keyFields` (type: `array`):

Fields that identify an item, e.g. url or id, or both. Dot paths such as meta.id work.

## `mode` (type: `string`):

dedup keeps the first item per key. merge combines items with the same key. The diff modes need Previous dataset.

## `previousDatasetId` (type: `string`):

Only for the diff modes: the dataset of the earlier run to compare with.

## `inlineItems` (type: `array`):

JSON objects to process. Used only when Datasets is empty. The example shows one duplicate.

## `trimValues` (type: `boolean`):

Ignore leading and trailing spaces when comparing.

## `ignoreCase` (type: `boolean`):

Treat ABC and abc as the same key. Output values stay unchanged.

## `stripUrlQuery` (type: `boolean`):

For URL keys: ?utm=... and #section do not make a new item.

## `ignoreFields` (type: `array`):

diff_changes: these fields do not count as a change, e.g. scrapedAt.

## `maxInputItems` (type: `integer`):

Safety limit per dataset side, e.g. 200000.

## Actor input object example

```json
{
  "keyFields": [
    "url"
  ],
  "mode": "dedup",
  "inlineItems": [
    {
      "url": "https://example.com/a",
      "title": "First"
    },
    {
      "url": "https://example.com/b",
      "title": "Second"
    },
    {
      "url": "https://example.com/a",
      "title": "First again"
    }
  ],
  "trimValues": true,
  "ignoreCase": false,
  "stripUrlQuery": false,
  "ignoreFields": [
    "scrapedAt"
  ],
  "maxInputItems": 200000
}
```

# Actor output Schema

## `items` (type: `string`):

No description

## `summary` (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 = {
    "keyFields": [
        "url"
    ],
    "inlineItems": [
        {
            "url": "https://example.com/a",
            "title": "First"
        },
        {
            "url": "https://example.com/b",
            "title": "Second"
        },
        {
            "url": "https://example.com/a",
            "title": "First again"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("stevenkramp/dataset-dedup-delta-merge").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 = {
    "keyFields": ["url"],
    "inlineItems": [
        {
            "url": "https://example.com/a",
            "title": "First",
        },
        {
            "url": "https://example.com/b",
            "title": "Second",
        },
        {
            "url": "https://example.com/a",
            "title": "First again",
        },
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("stevenkramp/dataset-dedup-delta-merge").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 '{
  "keyFields": [
    "url"
  ],
  "inlineItems": [
    {
      "url": "https://example.com/a",
      "title": "First"
    },
    {
      "url": "https://example.com/b",
      "title": "Second"
    },
    {
      "url": "https://example.com/a",
      "title": "First again"
    }
  ]
}' |
apify call stevenkramp/dataset-dedup-delta-merge --silent --output-dataset

```

## MCP server setup

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

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/mfsQpN9V2GRQmyWu4/builds/TUWgBUpZNMwouyuPq/openapi.json
