# Text Diff: compare texts, files and web pages (`examsens.ai/text-diff`) Actor

Compares pairs of texts, text files or web pages line by line, then word by word or character by character. Returns counts, a similarity score, every change, a unified diff and a side by side HTML report.

- **URL**: https://apify.com/examsens.ai/text-diff.md
- **Developed by:** [Ed Rayyis](https://apify.com/examsens.ai) (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

from $1.60 / 1,000 comparison completeds

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

## Text Diff: compare texts, files and web pages

Compare two versions of a text and see exactly what changed. Each side can be pasted text, a text file URL or a web page URL. Compare one pair or hundreds in one run.

### What you get for each pair

- Whether the two are identical, and a similarity score from 0 to 1
- Lines added, removed, changed and unchanged
- Words (or characters) added, removed and unchanged
- A list of every change: its type (added, removed, changed), the old and new text, and the line number on each side
- A unified diff, the format `git diff` and `patch` use, saved as a `.diff` file
- A side by side HTML report with removed words struck through in red and added words in green. Long unchanged stretches fold into a line such as "9 unchanged lines". It follows the reader's light or dark setting.

### How it compares

Lines are matched first. Changed lines are then compared word by word (the default), character by character, or left as whole lines. Word mode shows that "3 to 5 days" became "2 to 4 days" by marking only the four numbers, not the whole line.

Options:

- Ignore case
- Ignore whitespace: runs of spaces and tabs count as one space, and spaces at the ends of a line are ignored
- Ignore blank lines
- Web pages: compare the visible text (scripts, styles and markup removed, one line per block such as a paragraph or list item), or the HTML source
- Context lines around each change (default 3), and an option to show every line in the report

The unified diff always lists the lines as written. The ignore options apply to the counts, the change list and the HTML report.

### Input

- Original and Modified: one pair, each side text or a URL
- More pairs: a JSON list such as `[{"label": "pricing page", "original": "https://...", "modified": "https://..."}]`
- Compare changed lines by: word, character or line
- Ignore case, ignore whitespace, ignore blank lines
- Web pages compare: visible text or HTML source
- Context lines, save HTML report, show all lines in the report

URLs must answer HTTP 200 and be 10 MB or smaller. Character mode takes up to 400,000 characters per pair.

### Output

Dataset: one item per pair with `label`, `ok`, `original`, `modified` (the URL, or "original" and "modified" for pasted text), `originalType` and `modifiedType` (text, file, web page text or web page source), `identical`, `similarity`, the line and word counts, `changeCount`, `changes` (the first 500), `unifiedDiff` (the first 100,000 characters), `diffUrl` and `reportUrl`. The full diff and the report are in the key-value store.

A pair that cannot be compared gets `ok: false` and an `error`, such as a URL answering HTTP 404 or a pair entry that is not an object. The other pairs still run.

### Pricing

Pay per event: one event per pair compared. A pair that fails is not charged. The run stops when it reaches the maximum charge you set.

### Scope and conduct

The actor downloads each URL you list once per pair and stores nothing beyond the run's own storage.

### Support

Questions and problems: the Issues tab on this page.

# Actor input Schema

## `original` (type: `string`):

The original text, or the http or https URL of a web page or text file.

## `modified` (type: `string`):

The changed text, or a URL.

## `pairs` (type: `array`):

Compare many pairs in one run. Each entry is an object with "original", "modified" and an optional "label". Each side is text or a URL.

## `granularity` (type: `string`):

Lines are always matched first. Changed lines are then compared word by word, character by character, or left as whole lines.

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

Treat capital and small letters as equal.

## `ignoreWhitespace` (type: `boolean`):

Treat runs of spaces and tabs as one space, and ignore spaces at the start and end of a line.

## `ignoreBlankLines` (type: `boolean`):

Leave empty lines out of the comparison.

## `urlContent` (type: `string`):

For a URL that returns an HTML page: compare the visible text, or the HTML source. Other files are always compared as they are.

## `contextLines` (type: `integer`):

Unchanged lines shown around each change in the unified diff and the HTML report.

## `htmlReport` (type: `boolean`):

Save a side by side HTML report with changes highlighted for each pair.

## `fullReport` (type: `boolean`):

Show every unchanged line in the HTML report, instead of only the context lines.

## Actor input object example

```json
{
  "original": "The quick brown fox jumps over the lazy dog.\nShipping takes 3 to 5 days.\nReturns are free.",
  "modified": "The quick red fox jumps over the lazy dog.\nShipping takes 2 to 4 days.\nReturns are free.\nGift wrap is available.",
  "pairs": [
    {
      "label": "robots.txt",
      "original": "https://www.python.org/robots.txt",
      "modified": "https://www.djangoproject.com/robots.txt"
    }
  ],
  "granularity": "word",
  "ignoreCase": false,
  "ignoreWhitespace": false,
  "ignoreBlankLines": false,
  "urlContent": "text",
  "contextLines": 3,
  "htmlReport": true,
  "fullReport": false
}
```

# Actor output Schema

## `results` (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 = {
    "original": `The quick brown fox jumps over the lazy dog.
Shipping takes 3 to 5 days.
Returns are free.`,
    "modified": `The quick red fox jumps over the lazy dog.
Shipping takes 2 to 4 days.
Returns are free.
Gift wrap is available.`,
    "pairs": [
        {
            "label": "robots.txt",
            "original": "https://www.python.org/robots.txt",
            "modified": "https://www.djangoproject.com/robots.txt"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("examsens.ai/text-diff").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 = {
    "original": """The quick brown fox jumps over the lazy dog.
Shipping takes 3 to 5 days.
Returns are free.""",
    "modified": """The quick red fox jumps over the lazy dog.
Shipping takes 2 to 4 days.
Returns are free.
Gift wrap is available.""",
    "pairs": [{
            "label": "robots.txt",
            "original": "https://www.python.org/robots.txt",
            "modified": "https://www.djangoproject.com/robots.txt",
        }],
}

# Run the Actor and wait for it to finish
run = client.actor("examsens.ai/text-diff").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 '{
  "original": "The quick brown fox jumps over the lazy dog.\\nShipping takes 3 to 5 days.\\nReturns are free.",
  "modified": "The quick red fox jumps over the lazy dog.\\nShipping takes 2 to 4 days.\\nReturns are free.\\nGift wrap is available.",
  "pairs": [
    {
      "label": "robots.txt",
      "original": "https://www.python.org/robots.txt",
      "modified": "https://www.djangoproject.com/robots.txt"
    }
  ]
}' |
apify call examsens.ai/text-diff --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,examsens.ai/text-diff"
        }
    }
}
```

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/3Sf2urW6oN2BooYtk/builds/WyqHufh7ZevVNPA7B/openapi.json
