# Merge & Deduplicate Datasets: Remove Duplicates, Only New Rows (`greenrun/dataset-merge-dedup`) Actor

Merge Apify datasets with CSV, TSV, JSON and JSON Lines files and drop duplicate rows by any fields or whole rows, matching URLs, e-mails, case and spacing smartly. Scheduled runs can return only rows that earlier runs did not. $0.05 per 1,000 unique rows, $0.001 per 1,000 rows read.

- **URL**: https://apify.com/greenrun/dataset-merge-dedup.md
- **Developed by:** [Greenrun](https://apify.com/greenrun) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.05 / 1,000 rows

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

## Merge & Deduplicate Datasets: Remove Duplicates, Only New Rows

Merge Apify datasets with CSV, TSV, JSON and JSON Lines files and drop duplicate rows by any fields or whole rows, matching URLs, e-mails, case and spacing smartly. Scheduled runs can return only rows that earlier runs did not. $0.05 per 1,000 unique rows, $0.001 per 1,000 rows read.

Give it the datasets of your scraper runs, links to CSV, TSV, JSON or JSON Lines files, or rows pasted as JSON, and get **one clean dataset with every row once**. Duplicates are found by the fields you choose (`url`, `email`, `name` + `city` ...) or by the whole row, after smart normalization: `https://www.shop.com/p/1/?utm_source=x` and `http://shop.com/p/1` are the same product, `ADA@Example.com` and `ada@example.com` the same person. With **only-new mode** a scheduled run returns just the rows your earlier runs have not returned yet. **You pay $0.05 per 1,000 unique rows written and $0.001 per 1,000 rows read**, duplicates included, with no fee per file or dataset. Made for scraper pipelines, lead lists, product catalogs and AI agents that collect data in several runs.

### What it does

- **Merges** any number of Apify datasets, public CSV, TSV, JSON and JSON Lines files (plain or gzip) and rows given in the input, in that order, into one dataset.
- **Removes duplicates** by one or more fields, dot paths for nested values (`seller.id`, `images.0`), or by the whole row when no field is given. The first copy is kept.
- **Normalizes before comparing**: web addresses without http/https, `www.`, default port, `#fragment`, trailing slash and tracking parameters (`utm_*`, `gclid`, `fbclid` ...), query parameters in any order; e-mails in any letter case; upper and lower case; extra whitespace; `1`, `1.0` and `"1"` are equal. The output keeps your original values.
- **Returns only new rows** when you want: the keys of written rows are remembered in a key-value store in your account (12 bytes per row), and later runs with the same memory name skip them.
- **Filters and trims**: skip rows without the required fields, keep only the output fields you list, add a `_source` field with the dataset or file each row came from, stop after a number of rows.
- **Reports** every source in the `RUN-REPORT` record: format detected, rows read, written, duplicates, seen before, filtered, rejected, and why a source could not be read.

### Why use it

- **$0.05 per 1,000 unique rows written, $0.001 per 1,000 rows read.** No fee per file or dataset; links that cannot be read cost nothing beyond the start of the run.
- **Large datasets in small memory.** Rows are streamed from the datasets and files; memory holds a 12-byte key per unique row, never the rows. About 7 million unique rows fit in the default 1 GB.
- **Reliable runs.** Datasets are read in windows that resume after a broken connection, a run moved to another server by the platform continues where it stopped without writing or charging a row twice, and a silent server never keeps a run waiting longer than the run has paid for.
- **Works with limited permissions.** It reads only the datasets you pick (read-only), so it runs in the Apify MCP server and in integrations. No proxies, no login; robots.txt is respected for file links.
- **Built for AI agents.** One status message with the numbers (`Done: 249 unique rows written from 498 read; 249 duplicates (not written)`), inline rows in the input, and common field names of other merge Actors accepted (`fields`, `rows`, `maxItems` ...).

### How to use

#### In Apify Console

1. Pick your datasets in **Apify datasets**, or paste links in **File links**, or both.
2. Optional: list the fields in **Remove duplicates by these fields** (empty: whole rows); switch on **Only rows not written by earlier runs** and give a **Memory name** for scheduled runs.
3. Press **Start**. The **Output** tab shows the merged rows; download them as CSV, Excel, JSON or XML from the dataset. The `RUN-REPORT` record has the counts per source.

#### After another Actor (integration)

Add this Actor as an integration of your scraper, with `"datasetIds": ["{{resource.defaultDatasetId}}"]`, `"dedupeFields": ["url"]` and `"onlyNew": true`: every scraper run then ends with a dataset of the new rows only.

#### From an AI agent (MCP)

Connect any MCP client to the Apify MCP server with only this Actor as a tool:

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

#### Through the API

```bash
curl -X POST "https://api.apify.com/v2/acts/greenrun~dataset-merge-dedup/run-sync-get-dataset-items" \
  -H "Authorization: Bearer <APIFY_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"datasetIds": ["<DATASET_ID_1>", "<DATASET_ID_2>"], "dedupeFields": ["url"], "onlyNew": true, "memoryName": "my-shop-monitor"}'
```

Dataset IDs given through the API work like datasets picked in the form; a dataset can also be given by its name.

### Input

| Field | Default | Description |
|---|---|---|
| `datasetIds` | | Apify datasets to merge, in this order (picker in the form, IDs or names through the API). |
| `fileUrls` | | Links to CSV, TSV, JSON (an array, or one object with the rows inside) or JSON Lines files, plain or gzip. Read after the datasets. |
| `items` | | Rows as a JSON array of objects, read last. |
| `dedupeFields` | whole row | Rows with the same values in all these fields are duplicates. Dot paths for nested fields. |
| `normalizeUrls` | `true` | Compare web addresses and e-mails in their normalized form. |
| `dedupeIgnoreCase` | `true` | Ignore upper and lower case when comparing. |
| `trimWhitespace` | `true` | Ignore extra spaces, tabs and line breaks when comparing. |
| `keepRowsWithoutKey` | `true` | Rows where every field in `dedupeFields` is empty: keep each (on) or only the first (off). |
| `requiredFields` | | Rows where any of these fields is missing or empty are skipped (read, not written). |
| `onlyNew` | `false` | Skip rows written by earlier runs with the same memory name (read, not written). |
| `memoryName` | `default` | Runs with the same name share their memory (key-value store `dataset-merge-dedup-<name>` in your account, 12 bytes per row). |
| `outputFields` | all | Keep only these fields, in this order; a dot path becomes a field with the dotted name. |
| `addSourceField` | `false` | Add `_source`: `dataset:<ID>`, the file link or `input items`. |
| `maxRows` | `0` | Stop after this many unique rows; 0 means no limit. |
| `csvDelimiter` | detected | `,` `;` `|` or `tab`. |
| `itemsPath` | detected | For a JSON file that is one object: the dotted path to its list of rows, for example `data.items`. |

### Output

From a run on the Apify platform on 21 November 2026 with the prefilled input, two identical CSV files (the `main` and `master` copies of the country list from github.com/datasets): 249 rows, all from the first file.

```json
[
  {"Name": "Afghanistan", "Code": "AF"},
  {"Name": "Albania", "Code": "AL"},
  {"Name": "Algeria", "Code": "DZ"}
]
```

Status message: `Done: 249 unique rows written from 498 read; 249 duplicates (not written). All 2 sources read`. The same day, a scheduled-style run in only-new mode over a 20,000-row dataset whose first 19,900 rows were remembered from earlier runs wrote just the 100 new rows: `Done: 100 unique rows written from 20,000 read; 19,900 seen in earlier runs (not written)`.

`RUN-REPORT` (shortened) lists each source and the events the run charged:

```json
{
  "summary": "Done: 249 unique rows written from 498 read; 249 duplicates (not written). All 2 sources read",
  "totals": {"read": 498, "written": 249, "duplicates": 249, "seenBefore": 0, "filtered": 0, "rejected": 0, "notWritten": 0},
  "sources": [
    {"source": "https://raw.githubusercontent.com/datasets/country-list/main/data.csv", "type": "file", "status": "read", "format": "csv (delimiter ,)", "read": 249, "written": 249, "duplicates": 0, "error": null},
    {"source": "https://raw.githubusercontent.com/datasets/country-list/master/data.csv", "type": "file", "status": "read", "format": "csv (delimiter ,)", "read": 249, "written": 0, "duplicates": 249, "error": null}
  ],
  "dedupeFields": "whole row",
  "events": {"row-read": 50, "row": 249},
  "readUnits": 498,
  "startEvents": 1,
  "stoppedBecause": null
}
```

A source has the status `read`, `partial` (rows up to a broken place in the file were used), `failed`, `blocked` (robots.txt or the site refused), `not_found`, `stopped` (the run stopped in it at `maxRows`, the maximum cost or the memory limit) or `skipped` (the run stopped before it), with the reason in `error`.

### Pricing

Pay per event, no subscription. Each part of the work has its own small price, so every run pays for what it uses:

| Event | Price | When |
|---|---|---|
| Row | $0.00005 | One unique row written to the output, per started 100 KB of the row. |
| Row read | $0.00001 | Each started 10 rows read, summed over the whole run: datasets, files and the input, duplicates and filtered rows too; a row counts once per started 2 KB. A file counts per started 2 KB as it downloads, and its rows use that up first. |
| Only-new memory | $0.0002 | Each started 100,000 keys of the only-new memory, read or added in a run (at least one when only-new is on). |
| Actor start | $0.0045 per GB of memory | Charged by Apify when the run starts (the default memory is 1 GB). |

Examples: 1,000 rows read and 600 unique ones written cost $0.03 + $0.001 (100 row-read events), plus $0.0045 for the start. A daily only-new run after a scraper that reads 20,000 rows and finds 100 new ones costs $0.02 + $0.005 + $0.0002 + $0.0045 = $0.0297. Rows read are summed over the run and rounded up once: 1,005 rows read are 101 row-read events ($0.00101).

Not charged: rows of links and datasets that cannot be read (missing, blocked or broken). You can cap the cost of a run with the maximum charge in the run options; the run stops cleanly at that limit and the status message says so.

### Limits

- Formats: Apify datasets, CSV, TSV, JSON, JSON Lines, gzip-compressed or not. No Excel and no Google Sheets: save the sheet as CSV and use its link.
- File links must be public; no login, cookies or proxies, and robots.txt is respected. A file can be up to twice the run memory in size (1 GB memory: about 1.7 GB). A JSON file that is one object (not an array) is read whole, up to 100 MB.
- Waiting: the Actor waits for a server only as long as the run has already paid for (about 20 seconds for the first link at 1 GB of memory, more once rows come in). A link that stays silent fails, and when the links so far gave no data, the rest are skipped with the reason in `RUN-REPORT`.
- One row can be up to 8 MB (the dataset limit is 9 MB per row).
- Memory: 512 MB to 4 GB; one CPU core does the work, so more memory would not be faster. About 7 million unique rows (including the remembered rows of only-new mode) fit in the default 1 GB; the run stops cleanly and says so when the memory is full.
- The first copy of a duplicate is kept, in the order datasets, files, rows. Rows without a key (every dedupe field empty) are not remembered by only-new mode. Two only-new runs with the same memory name at the same time can each miss the other's new rows: run them one after another.

### FAQ

**Do you keep the data?** No. Results stay in your run's dataset and key-value store, and the only-new memory in the `dataset-merge-dedup-<name>` key-value store, all in your own Apify account under your data retention settings.

**How do I start the only-new memory again?** Use a new `memoryName`, or delete the `dataset-merge-dedup-<name>` key-value store in Storage.

**What did my run cost?** The `RUN-REPORT` record in the key-value store has `events`, the number of each event the run charged, and `readUnits`, the rows read in 2 KB units (one row-read event per started 10 of them), next to the counts per source (read, written, duplicates, seen before, filtered, rejected), examples of rejected rows and the reason for every source that could not be read.

**Can I get the result as CSV or Excel?** Yes: download the run's dataset in the format you need from the Storage tab or through the API (`format=csv`, `format=xlsx`).

**Something is wrong with a result?** Open an issue on the Actor's **Issues** tab with the input.

# Actor input Schema

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

Datasets to merge, in this order, for example the output of scraper runs. Pick them here, or give dataset IDs through the API (in an integration: {{resource.defaultDatasetId}}). The Actor runs with limited permissions, so it reads only the datasets given in this field, read-only.

## `fileUrls` (type: `array`):

Public links to CSV, TSV, JSON (an array, or one object with the rows inside) or JSON Lines files, plain or gzip-compressed, one per line. Read after the datasets. The format is detected from the link, the content type and the first bytes. robots.txt of each site is respected.

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

Rows given directly as a JSON array of objects, read after the datasets and files. Handy for AI agents and quick tests.

## `dedupeFields` (type: `array`):

Rows with the same values in all these fields are duplicates, for example url, or name and city. Dots reach nested fields (seller.id). Empty: whole rows are compared. The first copy is kept, in the order datasets, files, rows.

## `normalizeUrls` (type: `boolean`):

Web addresses match without http or https, www., the default port, the #fragment, a trailing slash and tracking parameters (utm\_\*, gclid, fbclid and similar), with query parameters in any order; e-mail addresses match in any letter case. Only for comparing: the output keeps the original values.

## `dedupeIgnoreCase` (type: `boolean`):

'ACME Inc' and 'acme inc' count as the same value.

## `trimWhitespace` (type: `boolean`):

Spaces, tabs and line breaks at the ends and repeated inside a value are ignored when comparing.

## `keepRowsWithoutKey` (type: `boolean`):

Rows where every field to remove duplicates by is empty cannot be compared. On: keep each of them (for example leads without an e-mail). Off: keep only the first one.

## `requiredFields` (type: `array`):

Rows where any of these fields is missing or empty are skipped (read, not written).

## `onlyNew` (type: `boolean`):

Remember the key of every written row and skip rows already written by earlier runs with the same memory name (they are read, not written). Ideal after a scheduled scraper: you get only new listings, jobs or products. The memory costs one 'memory-keys' event per started 100,000 remembered keys per run.

## `memoryName` (type: `string`):

Runs with the same name share their memory: a key-value store named dataset-merge-dedup-<name> in your account (12 bytes per remembered row). Use one name per project; a new name starts empty. Letters, digits and hyphens.

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

Keep only these fields, in this order; a dot path becomes a field with the dotted name (seller.id). Empty: every field.

## `addSourceField` (type: `boolean`):

Add a \_source field with dataset:<ID>, the file link or 'input items'.

## `maxRows` (type: `integer`):

Stop after this many unique rows. 0: no limit. The maximum cost per run in the run options also stops the run cleanly.

## `csvDelimiter` (type: `string`):

Character between CSV columns: , ; | or tab. Empty: detected from the header line.

## `itemsPath` (type: `string`):

For a JSON file that is one object: the dotted path to its list of rows, for example data.items. Empty: the longest list of objects in the first three levels.

## Actor input object example

```json
{
  "fileUrls": [
    "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
    "https://raw.githubusercontent.com/datasets/country-list/master/data.csv"
  ],
  "normalizeUrls": true,
  "dedupeIgnoreCase": true,
  "trimWhitespace": true,
  "keepRowsWithoutKey": true,
  "onlyNew": false,
  "memoryName": "default",
  "addSourceField": false,
  "maxRows": 0
}
```

# Actor output Schema

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

No description

## `report` (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 = {
    "fileUrls": [
        "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
        "https://raw.githubusercontent.com/datasets/country-list/master/data.csv"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("greenrun/dataset-merge-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 = { "fileUrls": [
        "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
        "https://raw.githubusercontent.com/datasets/country-list/master/data.csv",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("greenrun/dataset-merge-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 '{
  "fileUrls": [
    "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
    "https://raw.githubusercontent.com/datasets/country-list/master/data.csv"
  ]
}' |
apify call greenrun/dataset-merge-dedup --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,greenrun/dataset-merge-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/yldaQReqRE73p4dbz/builds/BEOGxjusH5GIwc1mm/openapi.json
