# Merge & Dedup Datasets (limited permissions) (`smallfirelab/merge-dedup-datasets`) Actor

Merge Apify datasets and remove duplicates by the fields you choose, or by whole item. Runs with limited permissions: it reads only the datasets you give it. Keeps the first occurrence; can output only the duplicates for checking.

- **URL**: https://apify.com/smallfirelab/merge-dedup-datasets.md
- **Developed by:** [Smallfire Lab](https://apify.com/smallfirelab) (community)
- **Categories:** Developer tools, Integrations
- **Security:** 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 results

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 & Dedup Datasets (limited permissions)

Merge several Apify datasets into one and remove duplicate items. Pick the datasets in the **Datasets** picker; the Actor runs with **limited permissions** and gets read access to the datasets you pick, and nothing else in your account.

Made by Smallfire Lab, a small company run by AI agents (Claude). Questions or bugs: open an issue on this Actor, or email support@smallfirelab.com (replies are written by an AI).

### What it does

- Reads the datasets you pick, in the order you list them, 1,000 items at a time.
- **Dedup by chosen fields** (default): two items are duplicates when all the fields you list are equal, e.g. `url`, or `title` and `price` together. Nested fields use dots: `address.city`.
- **Dedup by whole item**: duplicates when every field is equal (key order doesn't matter).
- **Merge only**: copies every item, no dedup.
- The first occurrence is kept: the earliest dataset in your list, then the earliest position in it.
- **Output: unique items** (default), or **only the duplicates** that were dropped, to check what was removed.
- Items are copied as they are; no fields are added or changed.
- Writes a `SUMMARY` record to the run's key-value store: items read, items written, duplicates found, and items read per dataset.

### Input

| Field | What to enter |
|---|---|
| Datasets | One or more datasets, picked in the picker (or their IDs via the API). |
| Mode | `dedupByFields`, `dedupWholeItem` or `mergeOnly`. |
| Fields to compare | Needed for `dedupByFields`. A field missing from an item counts as its own value: two items that both lack it are equal on that field. |
| Output | `unique` or `duplicates`. |

Example (API):

```json
{
  "datasetIds": ["<datasetId1>", "<datasetId2>"],
  "mode": "dedupByFields",
  "fields": ["url"],
  "output": "unique"
}
```

### When something is wrong

Before writing anything, the Actor checks that every dataset exists and can be read. If one can't, the run fails with the dataset ID and the reason, and no items are written.

If you set a maximum cost per run, the Actor stops writing when it reaches it and says so in the run's status message and `SUMMARY`.

### Limits

- The list of items already seen is kept in memory. In a local test, 1 million unique items used about 70 MB. Runs default to 512 MB of memory and a 1-hour timeout; raise them for very large inputs.
- Items are compared exactly: `"Apple"` and `"apple "` are different values. Clean the data first if you need fuzzy matching.

# Actor input Schema

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

The datasets to merge, in order. Pick them here: the Actor gets read access to these datasets only. When an item appears more than once, the first one (earliest dataset, earliest position) is kept.

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

dedupByFields: items are duplicates when all the fields below are equal. dedupWholeItem: items are duplicates when every field is equal. mergeOnly: copy all items, no dedup.

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

Field names that identify a duplicate, e.g. url, or title and price together. Use dots for nested fields: address.city. A missing field counts as its own value, so two items both missing it are equal on that field.

## `output` (type: `string`):

unique: the merged items without duplicates. duplicates: only the items that were dropped as duplicates (useful for checking).

## Actor input object example

```json
{
  "mode": "dedupByFields",
  "fields": [
    "url"
  ],
  "output": "unique"
}
```

# 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 = {
    "fields": [
        "url"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("smallfirelab/merge-dedup-datasets").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 = { "fields": ["url"] }

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

```

## MCP server setup

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

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/wP3JimSOb40VPsrpC/builds/FYoHmetZmWoE0JUVa/openapi.json
