# Merge Datasets: Deduplicate, Filter & Transform Apify Data (`registrydata/dataset-merge-dedup-transform`) Actor

Merge several Apify datasets into one, remove duplicates by any fields, filter rows, and rename or drop columns. Streams the data, so large datasets do not crash it.

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

## Pricing

$0.50 / 1,000 record writtens

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

## Dataset Merger: Merge, Deduplicate & Filter Apify Datasets

Combine the results of several Apify Actor runs into one clean dataset. Pick your datasets, say which fields make two records "the same", and get one deduplicated dataset back, optionally filtered and with columns renamed or removed. It streams records instead of loading everything into memory, reports exactly what it did, and never fails a whole run because one record is odd.

**Price: $0.50 per 1,000 records written.** Set a maximum cost per run and the run stops there. Details under [Pricing](#pricing).

Typical use: you run the same scraper daily, or several scrapers for the same niche, and you want one list without repeats.

### What it does

| Step | What happens |
|---|---|
| 1. Read | Reads every record of every dataset you pick, page by page, until the end. |
| 2. Filter (optional) | Keeps only records that match your rules (for example `price` greater than 50). |
| 3. Deduplicate | Removes repeats by the fields you choose, or by whole-record equality if you choose none. Keeps the first or the last occurrence. |
| 4. Reshape (optional) | Keeps only some fields, removes others, renames columns, and can add a `source_dataset` column. |
| 5. Write | Writes the result to this run's dataset and saves a `SUMMARY` record with counts per source. |

Order matters and is fixed: filters run first, deduplication second, reshaping last. Duplicates are therefore found on your original field names, not on renamed ones.

**Try it with no setup:** run it with the default (empty) input and it merges two small built-in sample datasets, so you can see the output format before pointing it at your own data.

### Use cases

- **Lead generation and sales:** merge daily scraper runs and keep one row per company URL or phone number.
- **Price and product monitoring:** union several marketplaces, then keep the latest record per product URL (`keep: last`).
- **Data teams:** clean a dataset before exporting it to a spreadsheet, a warehouse or a vector database.
- **Agencies:** deliver one deduplicated file per client from many runs.

### Input

Pick the datasets from your account with the dataset picker. Records from earlier datasets win ties when `keep` is `first`.

```json
{
  "datasets": ["<dataset picked from your account>", "<another dataset>"],
  "dedupeFields": ["url"],
  "keep": "first",
  "ignoreCase": true,
  "filters": [{"field": "price", "operator": "greaterThan", "value": 50}],
  "omitFields": ["rawHtml"],
  "renameFields": {"fullName": "name"},
  "addSourceField": true,
  "maxItems": 0
}
```

| Field | Meaning |
|---|---|
| `datasets` | Datasets to merge, chosen in the picker. The Actor can only read datasets you choose here. Leave empty (and leave `extraDatasetIds` empty) to run the built-in demo. |
| `extraDatasetIds` | Optional extra dataset IDs, names or Console URLs (for example from an integration or API call). Must be readable with this run's permissions. |
| `dedupeFields` | Fields that identify a duplicate. Dotted paths such as `address.city` reach nested values. Empty means "every field identical". |
| `keep` | `first` (default) or `last`. `last` reads the data twice. |
| `ignoreCase`, `trimWhitespace` | Make comparison forgiving (`HTTPS://X.com/a ` equals `https://x.com/a`). Whitespace trimming is on by default; case folding is off. |
| `keepItemsWithMissingKey` | On (default): records lacking a key field are kept as unique. Off: a missing field counts as null. |
| `filters`, `filterMode` | List of `{field, operator, value}`. Operators: `equals`, `notEquals`, `contains`, `notContains`, `startsWith`, `endsWith`, `greaterThan`, `greaterThanOrEqual`, `lessThan`, `lessThanOrEqual`, `matchesRegex`, `exists`, `notExists`, `isEmpty`, `isNotEmpty`. `filterMode` is `all` or `any`. |
| `pickFields`, `omitFields`, `renameFields` | Keep only these fields, drop these fields, rename fields. |
| `addSourceField`, `sourceFieldName` | Add a column naming the dataset each record came from. |
| `maxItems` | Stop after this many output records; 0 means unlimited. Also caps your spend. |

Numbers in text form compare as numbers (`"7"` is less than `50`), ISO 8601 dates compare correctly as text, and booleans match `true` and `false`.

### Output

Example output record (real output from a test run with the filter above):

```json
{
  "url": "https://shop.example.com/products/0",
  "name": "Product 0",
  "price": 71.51,
  "city": "Austin",
  "source_dataset": "demo-a"
}
```

Output records have the same fields as your inputs (after your reshaping). The `SUMMARY` record in the key-value store lists records read, filtered out, duplicates removed, unusable records skipped, and records written, per source dataset.

### Pricing

Pay per event: **$0.50 per 1,000 records written** (each record in the output dataset is one billed result; Apify may also show a small per-run start event on the pricing tab). You are charged only for records that reach the output, not for records that were read and discarded as duplicates or filtered out.

Example: merge 5 datasets holding 60,000 records that contain 20,000 duplicates. 40,000 records are written, so the run costs 40 x $0.50 = **$20.00**. Merging 1,000 unique records costs **$0.50**. Set `maxItems` to cap a run.

### Limits and honest notes

- **Access:** limited-permission Actors can only read datasets you select in the picker. That is an Apify security rule, and it is why you must choose datasets there (or use `extraDatasetIds` for datasets this run's token can read).
- **Memory:** duplicate detection keeps one 16-byte fingerprint per unique record in memory. In our synthetic benchmark, 1,000,000 records with 750,000 unique used about 130 MB (`keep: first`) or 150 MB (`keep: last`) of peak memory in the pipeline itself. Choose at least 512 MB for datasets above a few hundred thousand records, and 1 GB or more above a few million.
- **Records that are not JSON objects** (a bare string or number in a dataset) are skipped and counted in the summary.
- **Fingerprints** are 128-bit hashes, so an accidental false duplicate is astronomically unlikely (below 1 in 10^20 for 10 million records).
- **Unreadable or missing datasets fail the run** with a message naming the dataset, instead of producing an empty result.
- **Source datasets are never modified.**

### FAQ

**Is this legal to use?** Yes. It only processes datasets from your own Apify account. It does not access any website.

**Can I schedule it?** Yes. Use Apify Schedules, or run it automatically when another Actor finishes with an integration or webhook (pass the finished run's default dataset ID in `extraDatasetIds`).

**Can I call it from the API or an AI agent?** Yes, like any Actor: start it with the Apify API, client libraries or MCP, then read the result from the run's default dataset.

**What happens when the run is stopped or my spending limit is reached?** Records already written stay in the dataset. When your spending limit is reached, the run stops cleanly and the status message says so.

**Why did my duplicates not disappear?** Check for different spelling or case (turn on `ignoreCase`), differing key fields, or missing key fields (see `keepItemsWithMissingKey`). The summary shows how many records were unusable.

# Actor input Schema

## `datasets` (type: `array`):

The datasets to merge, in priority order. Records from earlier datasets win when duplicates are found and "Keep" is set to "first". Leave empty to run a demo on two small bundled sample datasets.

## `extraDatasetIds` (type: `array`):

Optional. Dataset IDs, names or Console URLs, for example the default dataset ID passed to this Actor by an integration. The Actor must be allowed to read them.

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

Two records are duplicates when all of these fields are equal. Use dots for nested fields, for example <code>address.city</code>. Leave empty to treat records as duplicates only when every field is identical.

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

Which record to keep from a group of duplicates. "last" needs a second pass over the data and takes about twice as long.

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

Compare text values without regard to upper or lower case when looking for duplicates.

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

Strip leading and trailing whitespace from text values when comparing records.

## `keepItemsWithMissingKey` (type: `boolean`):

When on, a record that lacks one of the duplicate fields is treated as unique and kept. When off, a missing field counts as null, so such records can be removed as duplicates of each other.

## `filters` (type: `array`):

Keep only records that match. Each filter has a <code>field</code>, an <code>operator</code> (equals, notEquals, contains, notContains, startsWith, endsWith, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual, matchesRegex, exists, notExists, isEmpty, isNotEmpty) and a <code>value</code>.

## `filterMode` (type: `string`):

"all" keeps records that match every filter; "any" keeps records that match at least one.

## `pickFields` (type: `array`):

Optional. When set, output records contain only these fields. Use dots for nested fields.

## `omitFields` (type: `array`):

Optional. Fields to drop from every output record, for example internal IDs or raw HTML.

## `renameFields` (type: `object`):

Optional. Map of old field name to new field name, for example <code>{"fullName": "name"}</code>.

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

Add a field that records which dataset each output record came from.

## `sourceFieldName` (type: `string`):

Name of the field added when "Add source dataset field" is on.

## `maxItems` (type: `integer`):

Stop after writing this many records. 0 means no limit. Use it to cap the cost of a run.

## Actor input object example

```json
{
  "extraDatasetIds": [],
  "dedupeFields": [
    "url"
  ],
  "keep": "first",
  "ignoreCase": false,
  "trimWhitespace": true,
  "keepItemsWithMissingKey": true,
  "filters": [],
  "filterMode": "all",
  "pickFields": [],
  "omitFields": [],
  "renameFields": {},
  "addSourceField": false,
  "sourceFieldName": "source_dataset",
  "maxItems": 0
}
```

# Actor output Schema

## `results` (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 = {
    "dedupeFields": [
        "url"
    ],
    "filters": [],
    "renameFields": {}
};

// Run the Actor and wait for it to finish
const run = await client.actor("registrydata/dataset-merge-dedup-transform").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 = {
    "dedupeFields": ["url"],
    "filters": [],
    "renameFields": {},
}

# Run the Actor and wait for it to finish
run = client.actor("registrydata/dataset-merge-dedup-transform").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 '{
  "dedupeFields": [
    "url"
  ],
  "filters": [],
  "renameFields": {}
}' |
apify call registrydata/dataset-merge-dedup-transform --silent --output-dataset

```

## MCP server setup

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

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/4EYz5BIyiCsTltz2s/builds/6NRA7CqQeCisIJtbV/openapi.json
