league/csv

CSV data manipulation made easy in PHP

Library
Composer
v9.28.0
3,480 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
91 /100 Excellent
Development Activity 92
Maintenance 92
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
79 /100 Good
Architecture 83
Code Quality 86
Innovation 72
Learning Curve 76

league/csv is a PHP library for reading, writing, and manipulating CSV data with a fluent, stream-based API. It provides a Reader and Writer built around PHP’s native SplFileObject/stream filters, a query layer for filtering, sorting, and selecting records without loading the whole file into memory, and converters for exporting CSV data to JSON, XML, and HTML.

Maintained by The League of Extraordinary Packages, it integrates with PDO, SQLite3, MySQLi, and PgSQL result sets, supports BOM detection and charset conversion, and guards against CSV formula injection when exporting to spreadsheet-consumed files. It targets modern PHP (8.2+) and is one of the most widely used CSV libraries in the PHP ecosystem.

What You Get

  • A Reader class for iterating CSV records lazily via generators, without loading the entire file into memory
  • A Writer class with configurable delimiters, enclosures, escape characters, and newline sequences
  • A fluent query layer (Query\Statement) for filtering, sorting, and selecting a subset of records
  • Converters for exporting CSV data to JSON, XML, and HTML tables
  • BOM detection/stripping, charset conversion, and EscapeFormula protection against CSV injection in spreadsheet apps

Common Use Cases

  • Importing large CSV files into a database or in-memory structures without exhausting memory
  • Exporting query results (from PDO, MySQLi, PgSQL, or SQLite3) directly to a downloadable CSV file
  • Building CSV-based ETL or data-transformation pipelines with filtering and column selection
  • Safely generating CSV exports for spreadsheet consumption, protected against formula-injection attacks

Under The Hood

Architecture - The library centers on an AbstractCsv base class shared by Reader and Writer, both wrapping a PHP stream resource (typically an SplFileObject or a raw stream) rather than reading the whole document into memory at once; records are exposed as PHP generators so a Reader can iterate multi-gigabyte files with constant memory. A separate Query namespace implements a statement/predicate system (filter, sort, offset/limit) that operates on the same lazy iterator, letting query criteria compose without materializing intermediate arrays. Format-conversion classes (JsonConverter, XMLConverter, HTMLConverter) consume the same Reader iterator interface, and CharsetConverter/Bom handle encoding detection and normalization at the stream-filter level via PHP’s stream_filter_register. Tech Stack - Pure PHP 8.2+, using PSR-4 autoloading (League\Csv namespace) and native PHP extensions (ext-filter, optionally ext-dom, ext-iconv, ext-mbstring, ext-pdo) rather than third-party dependencies; static analysis is enforced with PHPStan (including strict and deprecation-rule extensions) and code style with PHP-CS-Fixer. Code Quality - Test files are colocated with source files (e.g. ReaderTest.php next to Reader.php, 123 PHP source files across src/) using PHPUnit across three supported major versions (10/11/12), plus dedicated *Bench.php benchmark files run via phpbench for reader/writer performance regressions — an unusually rigorous quality bar combining unit tests, static analysis, and continuous benchmarking. API Design - The library exposes small, named entry points (Reader::createFromPath, Writer::createFromPath) and a fluent, chainable query builder (Statement::create()->where(...)->orderBy(...)), keeping common read/write use cases to one or two lines while still surfacing lower-level stream-filter hooks (EscapeFormula, CharsetConverter) for advanced encoding and security needs; the dedicated documentation site (csv.thephpleague.com) mirrors this progressive-disclosure structure.

Used by 7 apps in this directory

TypeScript
69%
BSD 3

Appwrite

Authentication · Databases · Developer Tools

57,760

Open-source backend platform with Auth, Databases, Storage, Functions, Messaging, Realtime, and Sites — deploy via Docker or use Appwrite Cloud.

View details
94
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 69%
PHP 31%
Updated yesterday
PHP
84%
Other

Invoice Ninja

Invoicing Finance · Project Management

10,311

Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.

View details
97
Repo Health
83
Technical
62
Dependency
Built with
PHP 84%
Updated 2 days ago
PHP
87%
AGPL 3.0

Kimai

Invoicing Finance · Project Management

5,095

Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.

View details
94
Repo Health
78
Technical
64
Dependency
Built with
PHP 87%
Updated today
PHP
55%
AGPL 3.0

Leantime

Collaboration · Productivity · Project Management

11,890

Project management built for ADHD, autism, and dyslexia — simple as Trello, powerful as Jira

View details
90
Repo Health
68
Technical
62
Dependency
Built with
PHP 55%
CSS 18%
Blade 14%
Updated 3 days ago
PHP
99%
MIT

Shlink

Developer Tools · Marketing

5,366

Self-hosted PHP URL shortener with a full REST API, dynamic redirect rules, and real-time visit analytics under your own domain.

View details
84
Repo Health
83
Technical
73
Dependency
Built with
PHP 99%
Updated 3 days ago
PHP
47%
AGPL 3.0

solidtime

Invoicing Finance · Productivity

9,027

Modern open-source time tracker for freelancers and agencies with invoicing, multi-org support, and Toggl/Clockify migration built in.

View details
84
Repo Health
81
Technical
67
Dependency
Built with
PHP 47%
TypeScript 28%
Vue 22%
Updated 3 days ago
PHP
71%
MIT

Yaffa

Invoicing Finance

112

Self-hosted personal finance app for long-term financial planning with AI-powered transaction parsing and investment tracking.

View details
80
Repo Health
78
Technical
67
Dependency
Built with
PHP 71%
Vue 24%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers