# CSV Splitter - Split Large CSV Files by Rows or Parts (`kotaro-project/csv-splitter`) Actor

Split one large CSV or TSV file into smaller CSV files: every N rows, or into N files of about equal size. The header row is repeated in each part. Get a download link for every part plus one ZIP. Auto-detects delimiter and encoding (UTF-8, Shift_JIS). No login, no API key.

- **URL**: https://apify.com/kotaro-project/csv-splitter.md
- **Developed by:** [KOTARO project](https://apify.com/kotaro-project) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 files split

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/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

## CSV Splitter - Split Large CSV Files by Rows or Parts

Split one large CSV or TSV file into smaller CSV files that Excel, Google Sheets, import tools and email can handle.

### What it does

- Reads a CSV or TSV from a **public URL** (up to 200 MB) or **pasted text**.
- Splits it **every N rows** (for example 1,000 rows per file) or into **N files of about the same size**.
- **Repeats the header row** at the top of every part (turn this off for files without column names).
- Keeps quoted line breaks inside their cell, so rows are never cut in the middle.
- Auto-detects the delimiter (comma, tab, semicolon, pipe) and the encoding (UTF-8, UTF-16, Shift_JIS, Latin-1). The parts are always UTF-8.
- Gives a **download link for every part** and **one ZIP** with all parts.

### Input example

```json
{
  "csvUrl": "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
  "splitBy": "rows",
  "rowsPerFile": 100
}
```

### Output example

```json
{
  "files": 3,
  "rowsTotal": 249,
  "splitBy": "rows",
  "rowsPerFile": 100,
  "zipFile": "data_parts.zip",
  "zipDownloadUrl": "https://api.apify.com/v2/key-value-stores/<store>/records/data_parts.zip",
  "parts": [
    {"fileName": "data_part001.csv", "rows": 100, "firstRow": 1, "lastRow": 100},
    {"fileName": "data_part002.csv", "rows": 100, "firstRow": 101, "lastRow": 200},
    {"fileName": "data_part003.csv", "rows": 49, "firstRow": 201, "lastRow": 249}
  ]
}
```

### Pricing

One `file-converted` event per run that makes files (all parts and the ZIP together). An empty input returns a free note. If the file
cannot be downloaded or has no data rows, you get an error row and are not charged.

### Limits and safety

- Files up to 200 MB, up to 5,000,000 rows and 500 parts per run.
- Only public `http`/`https` addresses on the standard ports. Internal and private network addresses are refused.
- No login, no API key, nothing is stored outside your own Apify storage.
- Only use files you are allowed to process.

# Actor input Schema

## `csvUrl` (type: `string`):

A public link to the CSV or TSV file to split (up to 200 MB). Leave empty to use the pasted text below.

## `csvText` (type: `string`):

Used when no URL is given.

## `splitBy` (type: `string`):

Rows: a new file every N data rows. Files: the rows are shared between N files of about the same size.

## `rowsPerFile` (type: `integer`):

Used when splitting by rows. Data rows only; the header row is added on top of each file.

## `numberOfFiles` (type: `integer`):

Used when splitting by files. Up to 500.

## `hasHeader` (type: `boolean`):

When on, the first row is repeated at the top of every part. Turn off for files without column names.

## `outputDelimiter` (type: `string`):

Keep the same delimiter as the input, or write the parts with another one.

## `delimiter` (type: `string`):

Auto detects comma, tab, semicolon or pipe.

## `encoding` (type: `string`):

Auto tries UTF-8, UTF-16, Shift_JIS and Latin-1. The parts are always UTF-8.

## Actor input object example

```json
{
  "csvUrl": "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
  "splitBy": "rows",
  "rowsPerFile": 100,
  "numberOfFiles": 2,
  "hasHeader": true,
  "outputDelimiter": "same",
  "delimiter": "auto",
  "encoding": "auto"
}
```

# 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 = {
    "csvUrl": "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
    "rowsPerFile": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("kotaro-project/csv-splitter").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 = {
    "csvUrl": "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
    "rowsPerFile": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("kotaro-project/csv-splitter").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 '{
  "csvUrl": "https://raw.githubusercontent.com/datasets/country-list/main/data.csv",
  "rowsPerFile": 100
}' |
apify call kotaro-project/csv-splitter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,kotaro-project/csv-splitter"
        }
    }
}
```

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/fcHAiEtiCXBxfOh0J/builds/XEsiBY2Kp4Xesmndv/openapi.json
