Spyc

A simple, dependency-free YAML loader and dumper written in pure PHP.

Library
Composer
v0.6.3
731stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity0
Maintenance20
Community80
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
65/100Good
Architecture55
Code Quality62
Innovation68
Learning Curve90

Spyc is a lightweight YAML serialization library implemented entirely in pure PHP. Given a YAML document it returns a native PHP array you can use however you like, and given an array it produces a YAML string built from your data. It has no external dependencies and exposes both a static class API and a set of convenience functions, making it trivial to drop into any PHP project that needs to read or write configuration, log, or data-serialization files.

Supporting the YAML 1.0 specification, Spyc has been a widely adopted choice for PHP applications needing straightforward YAML handling without pulling in a larger framework component. Its single-file design and minimal requirements keep integration friction low.

What You Get

  • A pure-PHP YAML parser that turns YAML documents into native PHP arrays
  • A YAML dumper that serializes PHP arrays back into YAML strings
  • Both static-method (Spyc::YAMLLoad) and functional (spyc_load_file) entry points
  • Zero external dependencies and a single-file drop-in design
  • A PHPUnit test suite covering loading, dumping, indentation, quoting, and round-trips

Common Use Cases

  • Reading application or module configuration stored as YAML files
  • Serializing PHP data structures to human-readable YAML for logs or exports
  • Parsing YAML fixtures or data files in legacy PHP applications without a framework
  • Round-tripping structured data between PHP arrays and YAML documents

Under The Hood

Architecture - Spyc is built around a single Spyc class in Spyc.php (~36KB) that implements both the loader and the dumper, wrapped by a handful of top-level helper functions (spyc_load, spyc_load_file, spyc_dump) defined only if not already present. Loading walks the YAML document line by line, tracking indentation depth to build nested PHP arrays, while dumping recurses over PHP array structures to emit indented YAML. There is no separate lexer/parser split; parsing state is threaded through the class instance.

Tech Stack - Pure PHP with a minimum requirement of PHP 5.3.1 and no runtime dependencies. The only dev dependency is PHPUnit (4.3.*). Autoloading is done via a Composer files autoload entry that simply includes Spyc.php.

Code Quality - The public API is small and documented with PHPDoc blocks. A PHPUnit suite under tests/ (LoadTest, DumpTest, IndentTest, ParseTest, RoundTripTest, plus YAML fixtures) exercises the core load/dump/indent/quote/round-trip paths. The implementation predates modern PHP idioms and concentrates logic in one large class, but behavior is stable and well covered by the fixtures.

API Design - Getting started is trivial: a single require plus Spyc::YAMLLoad($file) or the functional spyc_load_file($file). The dual static/functional entry points and array-in/array-out contract mean almost no boilerplate. Naming is consistent (YAMLLoad, YAMLLoadString, YAMLDump), and the README communicates the entire usage surface in a few lines.

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