# CSV Delimiter Auto-Detect (`stellar_ballet_0bu/csv-delimiter-autodetect`) Actor

Detect the delimiter, quote char, header presence, and encoding of any CSV/TSV/PSV file from a small sample. Outputs a `delimiter_decision` row with confidence and alternatives.

- **URL**: https://apify.com/stellar\_ballet\_0bu/csv-delimiter-autodetect.md
- **Developed by:** [Nikita S](https://apify.com/stellar_ballet_0bu) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 delimiter decideds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## CSV Delimiter Auto-Detect

Stop guessing. Feed in any CSV/TSV/PSV/text file, get back a single decision row with the **delimiter**, **quote char**, **header presence**, **encoding**, **confidence**, and **top-2 alternatives**.

Pure JavaScript, zero dependencies. Pairs with every other CSV Actor in the portfolio (`csv-dedupe-normalizer`, `csv-schema-profiler`, `csv-coerce-types`, `csv-quality-scorecard`, `csv-join-enricher`, `csv-diff`, `csv-statistical-summary`).

### How it scores

For each candidate delimiter (`,` `\t` `;` `|` by default):

1. Split the sample into rows.
2. Find the most common column count.
3. Score the fraction of rows that have that count (consistency).
4. Score the per-column type consistency (numeric / date / text uniformity).
5. Detect header presence by checking whether row 0's types differ from the rest.

Composite score = `0.5 * consistency + 0.4 * typeUniformity + 0.1 * headerBonus`.

### Use cases

- The single most common "I can't load this CSV" pain in n8n / Make / Google Sheets — the file uses `;` (European Excel), `\t` (TSV), `|` (pipe), or `,` (US default) and the user doesn't know which.
- Auto-route files into the right downstream Actor: pass the detected `delimiter` into `csv-coerce-types` or `csv-dedupe-normalizer`.
- Audit a partner's data feed: "they keep sending PSV and we keep parsing it as CSV".

### Input

| Field | Description | Default |
|-------|-------------|---------|
| `text` | Inline sample text. Use this OR `url`. | — |
| `url` | Public URL of a CSV/TSV/PSV file. | — |
| `candidates` | Characters to consider (use `\t` for tab). | `,\t;|` |
| `sampleBytes` | Sample size to probe (1 KB to 64 KB). | 8192 |

### Output

```json
{
  "_kind": "decision",
  "url": null,
  "encoding": "utf-8",
  "delimiter": ";",
  "quoteChar": "double",
  "hasHeader": true,
  "rows": 4,
  "columnCount": 3,
  "confidence": 0.94,
  "alternatives": [
    { "delimiter": ",", "score": 0.41, "rows": 4, "columnCount": 1 },
    { "delimiter": "\\t", "score": 0.30, "rows": 4, "columnCount": 1 }
  ]
}
```

### Run locally

```bash
npm install
npm test     # 10 cases
```

### Pricing / cost expectations

Default 256 MB / 512 MB. Reads at most 64 KB of the input (configurable via `sampleBytes`). **Pay-per-event** scheduled to activate after public launch: 1 charge per `delimiter_decided` event.

### Related Actors

- [`csv-header-normalizer`](../csv-header-normalizer) — once you know the delimiter, normalize the headers.
- [`csv-schema-profiler`](../csv-schema-profiler) — per-column type inference.
- [`csv-dedupe-normalizer`](../csv-dedupe-normalizer) — dedupe + header normalization.
- [`csv-quality-scorecard`](../csv-quality-scorecard) — full data-quality scorecard.

### FAQ

**Does it detect the quote char?** Yes, both `'` and `"` are scored and the best is chosen.

**Does it handle UTF-8 BOM?** Yes — the `encoding` field is set to `utf-8-bom` and the BOM is stripped before scoring.

**Does it work on one-line samples?** Single-row CSVs get a low confidence score (the detector needs at least 2 rows to be confident).

# Actor input Schema

## `text` (type: `string`):

CSV/TSV/PSV text. Use this OR `url`.

## `url` (type: `string`):

Public URL of a CSV/TSV/PSV file.

## `candidates` (type: `string`):

Characters to consider. Use \t for tab. Default: ',\t;|'.

## `sampleBytes` (type: `integer`):

How much of the input to probe (1 KB to 64 KB).

## Actor input object example

```json
{
  "text": "name;age;city\nAlice;30;Riga\nBob;25;Berlin\nCarol;40;Madrid\nDave;35;Paris\n",
  "url": "",
  "candidates": ",\t;|",
  "sampleBytes": 8192
}
```

# Actor output Schema

## `decisionRow` (type: `string`):

Single dataset item with \_kind='decision', url, encoding, sampleBytes, delimiter, quote, hasHeader, confidence, topCandidates, scores (per-candidate score breakdown).

## `summary` (type: `string`):

Run summary mirroring the decision row plus url and sampleBytes.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("stellar_ballet_0bu/csv-delimiter-autodetect").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("stellar_ballet_0bu/csv-delimiter-autodetect").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call stellar_ballet_0bu/csv-delimiter-autodetect --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=stellar_ballet_0bu/csv-delimiter-autodetect",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/q3IfQWLhRUTCb5BBS/builds/50dqCTbgM9oPLyFeg/openapi.json
