PHPackages                             ilbee/csv-response - 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. ilbee/csv-response

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

ilbee/csv-response
==================

Symfony component allow you to respond CSV contents directly in your controller

1.9.0(3mo ago)2180.6k↑141%31MITPHPPHP &gt;=7.4 &lt;9CI passing

Since Mar 26Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/ilbee/csv-response)[ Packagist](https://packagist.org/packages/ilbee/csv-response)[ Docs](https://github.com/ilbee/csv-response)[ RSS](/packages/ilbee-csv-response/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (8)Versions (32)Used By (1)

CSV Response
============

[](#csv-response)

[![CI](https://github.com/ilbee/csv-response/actions/workflows/ci.yml/badge.svg)](https://github.com/ilbee/csv-response/actions/workflows/ci.yml)[![PHP](https://camo.githubusercontent.com/40934da6b7f36c6c656396b331b016e99b5147905f2f901b8bca24d29fb5f4d9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d383839324246)](https://www.php.net/)[![Symfony](https://camo.githubusercontent.com/28de928b5c3feafb671faf2d75f553530e9222e23a996c391ad6b43a7cc23585/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d352e34253230253743253230362e78253230253743253230372e78253230253743253230382e782d626c61636b)](https://symfony.com/)[![License](https://camo.githubusercontent.com/d6bc2b26794002c24d023acaab01b6dbb953c57ab9cb80ba5b8aa2f2bd5de99a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c7565)](LICENSE)

A Symfony component that lets you return CSV file downloads directly from your controllers.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Which class should I use?](#which-class-should-i-use)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)
- [Full Documentation](docs/index.md)

Features
--------

[](#features)

- **Two response classes** for different use cases:

ClassExtendsBest for`CSVResponse``Response`Small to medium datasets (buffered in memory)`StreamedCSVResponse``StreamedResponse`Large datasets (streamed row by row, constant memory)- Automatic header row generation from array keys (can be disabled)
- Configurable separator (semicolon by default, comma, etc.)
- Custom file name support
- DateTime objects are automatically formatted (configurable format)
- Optional UTF-8 BOM for Excel compatibility
- CSV injection protection (formula sanitization)
- Optional row limit (`maxRows`) to prevent unbounded memory usage
- Strict type handling: clear errors for unsupported object types
- Accepts arrays, iterables, generators, or callables as data source
- No configuration required — just install and use

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

[](#installation)

```
composer require ilbee/csv-response
```

Usage
-----

[](#usage)

### Basic example

[](#basic-example)

```
use Ilbee\CSVResponse\CSVResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Attribute\Route;

class ExportController extends AbstractController
{
    #[Route('/export', name: 'export_csv')]
    public function export(): CSVResponse
    {
        $data = [
            ['firstName' => 'Marcel', 'lastName' => 'TOTO'],
            ['firstName' => 'Maurice', 'lastName' => 'TATA'],
        ];

        return new CSVResponse($data);
    }
}
```

This triggers a download of `CSVExport.csv` with the content:

```
firstName;lastName
Marcel;TOTO
Maurice;TATA
```

### Streaming large exports

[](#streaming-large-exports)

```
use Ilbee\CSVResponse\StreamedCSVResponse;

class ExportController extends AbstractController
{
    #[Route('/export/large', name: 'export_large_csv')]
    public function exportLarge(UserRepository $repository): StreamedCSVResponse
    {
        // Callable is invoked at send-time — no data buffered in memory
        return new StreamedCSVResponse(function () use ($repository) {
            foreach ($repository->findAllIterator() as $user) {
                yield [
                    'id' => $user->getId(),
                    'email' => $user->getEmail(),
                    'name' => $user->getName(),
                ];
            }
        });
    }
}
```

### Custom file name and separator

[](#custom-file-name-and-separator)

```
use Ilbee\CSVResponse\CSVResponseInterface;

return new CSVResponse($data, 'users.csv', CSVResponseInterface::COMMA);
```

### UTF-8 BOM (for Excel)

[](#utf-8-bom-for-excel)

```
return new CSVResponse($data, 'users.csv', CSVResponseInterface::SEMICOLON, true);
```

### Custom date format

[](#custom-date-format)

```
return new CSVResponse($data, 'users.csv', CSVResponseInterface::SEMICOLON, false, 'd/m/Y');
```

### Limit number of rows

[](#limit-number-of-rows)

```
// Throws OverflowException if data exceeds 10 000 rows
return new CSVResponse($data, 'users.csv', CSVResponseInterface::SEMICOLON, false, 'Y-m-d H:i:s', true, true, 10000);
```

### Without header row

[](#without-header-row)

```
return new CSVResponse(
    $data,
    'users.csv',
    CSVResponseInterface::SEMICOLON,
    false,
    'Y-m-d H:i:s',
    false
);
```

Which class should I use?
-------------------------

[](#which-class-should-i-use)

ScenarioClassSmall datasets (&lt; 1000 rows)`CSVResponse`Need to access content after creation (`getContent()`)`CSVResponse`Large datasets or unknown size`StreamedCSVResponse`Database cursor / generator source`StreamedCSVResponse`Memory-constrained environment`StreamedCSVResponse`Both classes share the same constructor signature and support the same features. The only difference is how data is written to the response.

Contributing
------------

[](#contributing)

```
composer install
composer test          # PHPUnit
composer phpstan       # Static analysis
composer cs-check      # Code style check
composer cs-fix        # Auto-fix code style
```

Credits
-------

[](#credits)

Special thanks to [Paul Mitchum](https://github.com/paul-m) and [Dan Feder](https://github.com/dafeder) for their contributions.

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 55.1% of commits — single point of failure

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 ~130 days

Recently: every ~0 days

Total

15

Last Release

97d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/30441946?v=4)[ilbee](/maintainers/ilbee)[@ilbee](https://github.com/ilbee)

---

Top Contributors

[![ilbee](https://avatars.githubusercontent.com/u/30441946?v=4)](https://github.com/ilbee "ilbee (27 commits)")[![paul-m](https://avatars.githubusercontent.com/u/360238?v=4)](https://github.com/paul-m "paul-m (21 commits)")[![dafeder](https://avatars.githubusercontent.com/u/309671?v=4)](https://github.com/dafeder "dafeder (1 commits)")

---

Tags

exportcsvSymfony controller response

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.9k157.3M879](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

3.5k182.1M852](/packages/league-csv)[goodby/csv

CSV import/export library

9865.7M25](/packages/goodby-csv)[sonata-project/exporter

Lightweight Exporter library

44921.6M40](/packages/sonata-project-exporter)[kartik-v/yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)

1693.3M36](/packages/kartik-v-yii2-export)[handcraftedinthealps/goodby-csv

CSV import/export library

441.8M7](/packages/handcraftedinthealps-goodby-csv)

PHPackages © 2026

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