Dataset Merge & Deduplicate: Remove Duplicates
Pricing
from $0.30 / 1,000 row writtens
Dataset Merge & Deduplicate: Remove Duplicates
Merge up to 20 Apify datasets into one and dedup them: remove duplicate items by one or more fields (URL, e-mail, ID, nested paths) or the whole item. Keep the first or last copy, ignore case and spaces, keep chosen fields. Large datasets, resumes after migration, clear outcome.
Pricing
from $0.30 / 1,000 row writtens
Rating
0.0
(0)
Developer
Bardach Technologies
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
3 days ago
Last modified
Categories
Features
Share
Dataset Merge & Deduplicate (dedup) combines several of your Apify datasets into one and removes duplicate items by one or more fields: a URL, an e-mail, an ID, nested fields with dots (user.email), or the whole item. Choose whether the first or the last copy is kept, and whether upper and lower case or surrounding spaces count. The unique items are written to this run's dataset in the order your datasets were given, ready to export as CSV, Excel or JSON.
Datasets are read page by page, so a dataset does not have to fit in memory. If the run is moved to another server or restarted, it continues from its last saved position instead of starting over, and the output does not get a row twice and no row is charged twice (see Limits, "Resuming and charging"). Every run ends with a clear outcome (complete, stoppedEarly or incomplete), so an automation never mistakes a partial merge for a full one.
How to merge and deduplicate datasets
- In Dataset IDs, pick the datasets to merge from your account (through the API: pass dataset IDs), up to 20, in the order they should be read.
- In Fields that define a duplicate, list the key fields, for example
urloruser.email. Leave it empty to compare whole items. - Choose Keep the first or Keep the last (for example, list the datasets oldest first and keep the last to get the newest copy).
- Optional: ignore case and surrounding spaces, keep only some fields in the output.
- Click Start. The unique items are in the run's dataset; the
OUTPUTrecord says what was read, removed and written.
Use cases
- Combine scraper runs: merge the datasets of daily or weekly runs of any scraper into one list without repeats.
- Remove duplicate leads, products or listings by URL, ID, e-mail or a combination of fields.
- Keep the newest version of each record across runs (
keep: last). - Clean data before an export or import: one row per key, only the fields you need.
- Automations: call it from a schedule, a webhook or the API after other Actors finish, and check
outcomebefore using the result.
What it does
- Reads each dataset you list, in that order, a page at a time (default 1,000 items).
- Builds a key for every item from the fields you chose. Items with the same key are duplicates.
- Writes the first (or last) item of every key to the output dataset, optionally reduced to the fields you list.
- Saves a summary to the key-value store record
OUTPUT: items read per dataset, duplicates removed, rows written, and every dataset that could not be read, with the reason.
A dataset that does not exist, or that your account cannot read, is reported and skipped, and the other datasets are still merged. But then the output is missing rows, so the run ends as incomplete (see "How a run ends") and is marked failed unless you set allowPartial.
How a run ends
Every run ends in exactly one of three ways. The same word is used in the run's exit status, its status message (first word), the OUTPUT record (outcome) and this page. No run ends with a plain "Done".
| Outcome | What it means | Exit status | Status message starts with |
|---|---|---|---|
complete | Every dataset was read and merged in full. | success | Complete: |
stoppedEarly | The run stopped on purpose: your maximum charge was reached (stopReason: maxCharge), or it was about to run out of memory (stopReason: memory). What was written is a correct start of the result, in dataset order, and all of it was charged. The message says how to get the rest: start a new run with a higher maximum charge or more memory (it writes the whole result into its own dataset, so you pay for those rows again). | success for the maximum charge (your own limit); failed for memory (not your choice) | Stopped early |
incomplete | Data could not be read, so the output is missing rows: an unreadable dataset, a read that failed part-way, a dataset skipped because it lacks the key field, or keys lost with keep: last. The message names the datasets and, with keep: last, how many keys are missing. | failed, unless allowPartial is on (then success, but the message still starts with Incomplete) | Incomplete |
If a run is both stopped early and incomplete, it is incomplete. If no dataset could be read at all (every one unreadable or skipped), the run fails even with allowPartial, since there is no partial result to accept. A run that fails on bad input (Input problem: ...) writes no OUTPUT record. A refused resume (Cannot resume: ...) writes an OUTPUT with outcome: incomplete. A memory stop always fails the run, also with allowPartial. Automations should check outcome in OUTPUT, not only whether the run succeeded: a succeeded run can be stoppedEarly (maximum charge) or, with allowPartial, incomplete.
Why incomplete fails by default: with keep: last, a dataset that cannot be read in the second pass loses the keys whose last copy was in the unread part, so the output is not just shorter, it is wrong for those keys. A job that consumes the output of a succeeded run would not notice. Set allowPartial only if you accept that.
No datasets given: with an empty or missing datasetIds (for example the Store's automatic test with the default input) the run ends successfully at once, writes an OUTPUT summary with zeros and the message "No datasets given: nothing to merge", and charges nothing except Apify's start fee.
Checked when each dataset is opened, before any of its rows is charged: the run reads the first 1,000 items of the dataset. If no item in that sample has a usable key (a field you listed in fields is missing or null in every one of them), or a name in outputFields appears in none of them, that dataset is skipped with a clear message (status failed, none of its rows written or charged) and the run ends incomplete; if every dataset is skipped, nothing is written or charged at all. Fields that first appear after the first 1,000 items of a dataset are not caught: items with a null key then follow nullKeyHandling (keepAll writes and charges them, and nullKeyItems in the summary counts them). So what a wrong or absent key field can cost is bounded: nothing for a dataset whose first 1,000 items have no key, and otherwise at most the rows of that dataset, which you can cap with a maximum charge.
Input
| Field | What it does |
|---|---|
datasetIds | The datasets to merge, up to 20. In the Console you pick them from your account; through the API you pass dataset IDs. The run gets read-only access to the datasets you pick. |
fields | Fields that define a duplicate, up to 20. Use dots for nested fields (user.email, tags.0). Empty (the default, in the Console and through the API) means the whole item is compared. |
keep | first (default) or last. last reads every dataset twice. |
caseInsensitive | Compare text without regard to case. Default off. |
trimWhitespace | Compare text without leading and trailing spaces. Default off. |
outputFields | Optional list of fields to write. Duplicates are still judged on the full item. A name found in none of a dataset's first 1,000 items skips that dataset (see above). An item that has none of the listed fields is not written and not charged (emptyAfterProjection). A list element picked with a number (tags.0) is written as an object ({"tags": {"0": ...}}). |
nullKeyHandling | What to do with items where a dedup field is missing or null: keepAll (default), drop, or groupTogether (treat them as one group, so only one is kept). |
pageSize | Items per read, 1 to 10,000. Default 1,000. |
saveStateEverySeconds | How often progress is saved for resuming. Default 15. |
allowPartial | Default off. Off: a run that ends incomplete is marked failed. On: it succeeds, but its status message and OUTPUT still say incomplete. |
{"datasetIds": ["WkzbQMuFYuamGv3YF", "k5Rn8bqX2eVd7LpUs"],"fields": ["url"],"keep": "first","caseInsensitive": true,"trimWhitespace": true,"outputFields": ["url", "title", "price"],"nullKeyHandling": "keepAll"}
Output
One dataset item per unique input item, unchanged apart from outputFields:
{ "url": "https://shop.example/item/42", "title": "Blue mug", "price": 9.5 }
The OUTPUT record in the key-value store:
{"keep": "first","fields": ["url"],"datasets": [{ "datasetId": "WkzbQMuFYuamGv3YF", "status": "ok", "itemsRead": 5000, "duplicatesRemoved": 120,"nullKeyDropped": 0, "nullKeyItems": 3, "skippedNotObject": 0, "itemsWritten": 4880 },{ "datasetId": "k5Rn8bqX2eVd7LpUs", "status": "failed", "itemsRead": 0, "itemsWritten": 0,"error": "dataset not found or not readable with this run's access (ValueError: ...)" }],"itemsRead": 5000,"duplicatesRemoved": 120,"itemsWritten": 4880,"failedDatasets": [ { "datasetId": "k5Rn8bqX2eVd7LpUs", "reason": "dataset not found or not readable ..." } ],"emptyAfterProjection": 0,"keysMissing": 0,"outcome": "incomplete","statusMessage": "Incomplete: the output is missing rows. Not read completely: k5Rn8bqX2eVd7LpUs (...)","stopReason": null,"stoppedAtMaxCharge": false,"stoppedAtMemoryLimit": false,"maxDistinctKeys": 2569011,"resumed": false}
A dataset status is ok, partial, failed or notRead. ok: read and merged completely, in every pass. partial: read or merged only in part (a read failed part-way, or the run stopped at your maximum charge or for memory while it was working on or past this dataset; with keep: last a stop during the first pass leaves every dataset at most partial). failed: nothing could be read, or the dataset was skipped (for example the key field is missing). notRead: the run stopped before it got to this dataset. Datasets with a read problem are also listed in failedDatasets. After a stop, no dataset that was not fully merged shows ok.
With keep: last, a dataset that cannot be read in the second pass loses the rows that were not read, and also every key whose last copy was in that unread part: earlier copies of such a key were already skipped as duplicates. The dataset's keysMissing (and the total keysMissing) counts those keys, and the Incomplete message names the number. Run again, or use keep: first, if you cannot accept that. Datasets after the failed one are merged completely.
How keys are compared
- Values are compared as stored, with three exceptions: text is normalised to one Unicode form (so "café" typed with a combined or a separate accent matches),
1and1.0are equal, and key order inside nested objects does not matter. - The text
"1"and the number1are different.trueand1are different. - Nested objects and lists can be used as keys.
- An item has a null key when any chosen field is missing or null. An empty text,
0or an empty list is a normal value. - Items that are not JSON objects are skipped and counted as
skippedNotObject.
Pricing
Pay per event, no subscription; Apify platform usage is not billed on top. How much does it cost? Merging datasets into 10,000 unique rows costs about USD 3.00 (USD 0.30 per 1,000 rows written plus USD 0.002 per run); duplicates removed are free. Exactly what is charged, on every path:
- Actor start: USD 0.00005 per run, charged by Apify (not by this Actor's code) when the run starts. It applies to every run: also runs that end at once on empty input, fail on bad input, cannot read any dataset, or write nothing. How the platform scales it with run memory is not documented in this repository; check your run's charges.
- Row written: USD 0.0003 per row written to the output dataset (USD 0.30 per 1,000 rows), charged right after the row is written.
- Merge run: USD 0.002 once per run, charged right after the first row is written, also if the run later stops early or fails. Not charged when no row was written. A resumed run does not pay it again.
| Path | Start fee | Merge run | Rows |
|---|---|---|---|
| Empty input, bad input, no dataset readable, every dataset skipped | yes | no | no |
complete | yes | yes (if a row was written) | rows written |
stoppedEarly at your maximum charge | yes | yes | rows written so far (the run stops before the next row would exceed the maximum) |
stoppedEarly for memory (run failed) | yes | yes, if a row was written | rows written so far |
incomplete (failed or with allowPartial) | yes | yes, if a row was written | rows written; unreadable or skipped datasets add none |
| Crash between writing and charging a page, then resume | yes | once | up to one page of rows per crash can stay uncharged; none is charged twice |
Resume refused (Cannot resume) | yes | not again | nothing new; the rows already written stay and stay charged |
Duplicates, dropped items, skipped datasets and rows that are empty after outputFields are never charged. Rows are pushed first and charged right after, so charges never exceed the rows in the output.
Limits and good to know
-
Up to 20 datasets and 20 dedup fields per run. Only datasets your account can read are used; the run uses its own access, not a token you type in.
-
Memory. Keys are kept as 128-bit hashes, never as the original values (two different keys are treated as equal with a probability of about 10^-25 at 10 million distinct keys: negligible). At every page the run compares the real memory of its process (RSS) with the run's memory limit (
ACTOR_MEMORY_MBYTES, set by the platform; 512 MB if it is not set, as in a local run) and stops cleanly when the process memory plus the next doubling of its key table (the old and the new table are alive together: 270 MB in one step at 5 million keys) reaches 80% of it, so the platform's out-of-memory kill is not reached; the rest is headroom for one page and a state save. It also stops if the number of distinct keys passes a planned ceiling. On a stop theOUTPUTsummary is written (stopReason: memory,outcome: stoppedEarly), the rows already written stay and are charged, the run is marked failed (see "How a run ends"), and withkeep: lastnothing is written yet when the first pass stops.Measured on Linux, in this Actor's own Docker image (Python 3.12, Apify SDK imported, real engine and one state save included, peak RSS of the process;
tests/measure_memory.py). The platform's own containers can differ somewhat.Distinct keys keep: firstpeakkeep: lastpeak200,000 75 MB 103 MB 1,000,000 134 MB 208 MB 2,000,000 212 MB 325 MB 3,000,000 364 MB 510 MB The base (interpreter + Apify SDK) is about 56 MB; the worst cost seen was up to 108 bytes per key above it with
keep: firstand 160 withkeep: last(246 at 200,000 keys). The planning ceiling below uses 130 and 190 bytes per key plus 80 MB of base, which leaves only about 1.2 times margin over the worst measured cost, plus the table doubling, up to 80% of the memory. These are the distinct keys the run plans for; the live check above is what actually protects the run, and it stops earlier or later than this table if your items are large or the platform's memory use differs. In stop tests inside Docker with the run's memory limit enforced (256 to 2,048 MB, both modes), the run stopped cleanly every time and peaked at 35% to 50% of the limit:Run memory keep: firstkeep: last256 MB (minimum) 748,521 524,288 512 MB (default) 2,097,152 1,289,196 1,024 MB 4,194,304 3,019,898 2,048 MB 8,440,230 6,481,303 4,096 MB (maximum) 17,525,737 13,404,112 Only up to 3,000,000 keys and memory limits up to 2,048 MB were measured; the 4,096 MB tier is extrapolated. Items that are several MB each need a smaller
pageSize, because a page of them is held in memory too. Items without a key (null keys) use no key memory. -
Saved state. For resuming, the key hashes are saved in records of at most 4 MB each (16 bytes per key, 24 with
keep: last), so the size of one record does not depend on the number of keys. The platform's record size limit is not documented that I could verify; 4 MB is kept well under the commonly quoted 9 MB. Saving takes time in proportion to the number of keys, so the run saves no more often than once persaveStateEverySeconds, and spaces saves out so that they take at most about a tenth of the run time. -
Resuming and charging. The run saves its state before it writes the first row, so a restart at any point resumes. Rows are written first and charged right after, so a crash between the two leaves rows that were written but not charged (you can be under-charged by up to one page of rows per crash; no row is charged twice). On a restart the run reads the output dataset itself, from the row count in the saved state to its end, to learn exactly how many rows were already written after that state, and skips that many. It does not use the dataset's item count, which can lag. Because a read right after a migration might not show the newest rows yet, the run first reads the output repeatedly, a few seconds apart, until two reads in a row agree (at most 10 reads), and only then counts. If the output holds fewer rows than the saved state says, fewer than were charged, cannot be read, or its count never settles, the run fails with a clear message instead of guessing: the message says how many rows were already written to the output and how many were charged (they stay), an
OUTPUTrecord withoutcome: incompleteandresumeRefused: trueis written, and you are told to start a new run (it writes the whole result into its own dataset, so its rows are charged again). This was tested by killing the run at every write, state-save and charge boundary (also in the middle of a push, and repeatedly during resumes) in both modes: zero duplicate rows, the output equal to the reference result, charges never above the rows present. -
Do not change the source datasets while the run is working. With
keep: lastthey are read twice; a dataset that has fewer items in the second pass is reported aspartialwithkeysMissing. -
The output dataset has no fixed columns, so the Output tab shows a plain table.
-
Items are copied as they are. Very large items slow reading; lower
pageSizefor them. -
Items nested deeper than 50 levels, or a value that cannot be turned into a key, count as having a null key (no message per item).
-
Not measured on the platform: a run of one million rows, the real RSS base, and whether a 4 MB state record is accepted (no token was used, local only).
keep: lastneeds about twice the read time ofkeep: first; set a run timeout that fits your data.
FAQ
Can I merge datasets from other accounts? Only if the run's account can read them. Others are reported as not readable.
Can I keep the newest item instead of the oldest? Yes: keep: last, with the datasets listed oldest first.
What if a field is missing in some items? Those items have a null key. Choose keepAll, drop or groupTogether.
Can I run it from my own code or an AI agent? Yes: through the Apify API, a client library (Python, JavaScript), an integration (Make, Zapier, n8n), a webhook after another Actor's run, or the Apify MCP server.
Related Actors from the same developer: Offline Phone Number Validator & Formatter cleans and normalises phone numbers to E.164 before you deduplicate them.