league/csv

CSV data manipulation made easy in PHP

Library
Composer
v9.28.0
3,480stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
77/100Good
Development Activity68
Maintenance60
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture83
Code Quality86
Innovation72
Learning Curve76

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
61%
BSD 3

Appwrite

Developer Tools · Databases · Authentication

57,057

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

View details
92
Repo Health
81
Technical
71
Dependency
Built with
TypeScript61%
PHP38%
Updated today
PHP
85%
Other

Invoice Ninja

Invoicing Finance · Project Management

10,008

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
PHP85%
XSLT10%
Updated 2 days ago
PHP
86%
AGPL 3.0

Kimai

Invoicing Finance · Project Management

4,918

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
63
Dependency
Built with
PHP86%
Updated today
PHP
48%
AGPL 3.0

Leantime

Productivity · Project Management · Collaboration

11,391

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

View details
90
Repo Health
68
Technical
67
Dependency
Built with
PHP48%
CSS20%
Blade17%
Updated 4 days ago
PHP
99%
MIT

Shlink

Developer Tools · Marketing

5,223

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

View details
86
Repo Health
83
Technical
72
Dependency
Built with
PHP99%
Updated 1 weeks ago
PHP
45%
AGPL 3.0

solidtime

Productivity · Invoicing Finance

8,860

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
70
Dependency
Built with
PHP45%
TypeScript30%
Vue23%
Updated yesterday
PHP
71%
MIT

Yaffa

Invoicing Finance

108

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

View details
78
Repo Health
78
Technical
72
Dependency
Built with
PHP71%
Vue24%
Updated 2 days ago

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

Search