PHPackages                             keboola/csv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. keboola/csv

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

keboola/csv
===========

Keboola CSV reader and writer

4.1.0(2y ago)1451.8M—2%36[3 PRs](https://github.com/keboola/php-csv/pulls)20MITPHPPHP &gt;=7.4

Since Oct 1Pushed 2y ago20 watchersCompare

[ Source](https://github.com/keboola/php-csv)[ Packagist](https://packagist.org/packages/keboola/csv)[ Docs](http://keboola.com)[ RSS](/packages/keboola-csv/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (38)Used By (20)

Keboola CSV reader/writer
=========================

[](#keboola-csv-readerwriter)

[![Latest Stable Version](https://camo.githubusercontent.com/6ffafb32e2ecd4756ecbe140479f2032eaf2e48a3f827fb99e9edf25d3fea18c/68747470733a2f2f706f7365722e707567782e6f72672f6b65626f6f6c612f6373762f762f737461626c652e737667)](https://packagist.org/packages/keboola/csv)[![License](https://camo.githubusercontent.com/69318da48c1f22b642933483326116ce4d8f1a19cd8daf1bb077bf7a47776dee/68747470733a2f2f706f7365722e707567782e6f72672f6b65626f6f6c612f6373762f6c6963656e73652e737667)](https://packagist.org/packages/keboola/csv)[![Total Downloads](https://camo.githubusercontent.com/8bb28b3f768318e15e632150050d423d74c242deeb2fcfb11d06033368562fca/68747470733a2f2f706f7365722e707567782e6f72672f6b65626f6f6c612f6373762f646f776e6c6f6164732e737667)](https://packagist.org/packages/keboola/csv)

The library provides a simple reader and writer for CSV files according to [RFC4180](https://tools.ietf.org/html/rfc4180). The library is licensed under the [MIT](https://github.com/keboola/php-csv/blob/master/LICENSE) license. The library provides classes `CsvReader` and `CsvWriter` for reading and writing CSV files. The classes are designed to be **immutable**and minimalistic.

Usage
-----

[](#usage)

### Read CSV

[](#read-csv)

```
$csvFile = new Keboola\Csv\CsvReader(__DIR__ . '/_data/test-input.csv');
foreach($csvFile as $row) {
	var_dump($row);
}
```

#### Skip lines

[](#skip-lines)

Skip the first line:

```
$csvFile = new \Keboola\Csv\CsvFile(
    $fileName,
    CsvFile::DEFAULT_DELIMITER,
    CsvFile::DEFAULT_ENCLOSURE,
    CsvFile::DEFAULT_ESCAPED_BY,
    1
)
foreach($csvFile as $row) {
	var_dump($row);
}
```

### Write CSV

[](#write-csv)

```
$csvFile = new Keboola\Csv\CsvWriter(__DIR__ . '/_data/test-output.csv');
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}
```

### Append to CSV

[](#append-to-csv)

```
$fileName = __DIR__ . '/_data/test-output.csv';
$file = fopen($fileName, 'a');
$csvFile = new Keboola\Csv\CsvWriter($file);
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}
fclose($file);
```

### Write CSV With Windows new-lines

[](#write-csv-with-windows-new-lines)

```
$csvFile = new Keboola\Csv\CsvWriter(
    'test-output.csv',
    CsvWriter::DEFAULT_DELIMITER,
    CsvWriter::DEFAULT_ENCLOSURE,
    "\r\n"
)
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}
```

Installation
------------

[](#installation)

The library is available as [composer package](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx). To start using this library in your project follow these steps:

**Install package:**

```
composer require keboola/csv
```

**Add autoloader in your bootstrap script:**

```
require 'vendor/autoload.php';
```

Read more in [Composer documentation](http://getcomposer.org/doc/01-basic-usage.md)

Development
-----------

[](#development)

Clone this repository and init the workspace with following command:

```
git clone https://github.com/keboola/php-csv.git
cd php-csv
docker-compose build
docker-compose run --rm dev composer install --no-scripts

```

Run the test suite using this command:

```
docker-compose run --rm dev composer tests

```

License
-------

[](#license)

MIT licensed, see [LICENSE](./LICENSE) file.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community38

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~117 days

Recently: every ~70 days

Total

36

Last Release

859d ago

Major Versions

1.4.2 → 2.0.02018-05-18

2.3.0 → 3.0.02022-05-10

v1.x-dev → 4.0.02023-04-06

3.4.0 → 4.1.02024-01-11

PHP version history (2 changes)1.3.0PHP &gt;=5.6

3.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/101dbf2551a0709ddab522f97669f13a2c4cc2d0a1e8d009f3af6ba80accb1a9?d=identicon)[Keboola](/maintainers/Keboola)

![](https://www.gravatar.com/avatar/f20f5be7cd67e3836d58407d46e2b083b1dd4c7e32c48c578128e5a78550794d?d=identicon)[Halama](/maintainers/Halama)

---

Top Contributors

[![odinuv](https://avatars.githubusercontent.com/u/4319320?v=4)](https://github.com/odinuv "odinuv (65 commits)")[![Halama](https://avatars.githubusercontent.com/u/903531?v=4)](https://github.com/Halama "Halama (30 commits)")[![AdamVyborny](https://avatars.githubusercontent.com/u/27994036?v=4)](https://github.com/AdamVyborny "AdamVyborny (24 commits)")[![michaljurecko](https://avatars.githubusercontent.com/u/19371734?v=4)](https://github.com/michaljurecko "michaljurecko (16 commits)")[![zajca](https://avatars.githubusercontent.com/u/180148?v=4)](https://github.com/zajca "zajca (9 commits)")[![ondrajodas](https://avatars.githubusercontent.com/u/12143866?v=4)](https://github.com/ondrajodas "ondrajodas (8 commits)")[![kachnitel](https://avatars.githubusercontent.com/u/4067705?v=4)](https://github.com/kachnitel "kachnitel (6 commits)")[![tomasfejfar](https://avatars.githubusercontent.com/u/642928?v=4)](https://github.com/tomasfejfar "tomasfejfar (3 commits)")[![ujovlado](https://avatars.githubusercontent.com/u/419849?v=4)](https://github.com/ujovlado "ujovlado (2 commits)")[![mike182uk](https://avatars.githubusercontent.com/u/991592?v=4)](https://github.com/mike182uk "mike182uk (1 commits)")[![derrabus](https://avatars.githubusercontent.com/u/1506493?v=4)](https://github.com/derrabus "derrabus (1 commits)")[![barnabywalters](https://avatars.githubusercontent.com/u/968350?v=4)](https://github.com/barnabywalters "barnabywalters (1 commits)")

---

Tags

csvrfc4180

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/keboola-csv/health.svg)

```
[![Health](https://phpackages.com/badges/keboola-csv/health.svg)](https://phpackages.com/packages/keboola-csv)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

3.5k166.1M646](/packages/league-csv)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.2k57.6M131](/packages/openspout-openspout)[goodby/csv

CSV import/export library

9555.6M23](/packages/goodby-csv)[sonata-project/exporter

Lightweight Exporter library

44920.9M35](/packages/sonata-project-exporter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
