Skip to content
pubscout

pubspec_parse

1.7.0, released 4 weeks ago by tools.dart.dev

Parse pubspec.yaml files with a type‑safe API and detailed error reporting.

WASM-readyRock solid
$ flutter pub add pubspec_parse
Source repository

What it does

Provides classes to read and write pubspec.yaml content, exposing hosted, git, and path dependencies as typed objects. Supports lenient parsing, preserves map spans, and can serialize back to a Map.

AI-written summary of version 1.7.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to validate or transform a pubspec.yaml in a tool or CI step
  • You are building a CLI that inspects package metadata
  • You want a robust, typed representation of pubspec fields for analysis

Skip it when

  • Parsing arbitrary YAML where a generic parser is sufficient
  • Runtime pubspec parsing in a production Flutter app where size matters

Strengths

  • Typed API for all pubspec fields
  • Rich, precise error messages via checked_yaml
  • Supports latest Dart pubspec features (git tag_pattern, falseSecrets, hooks, platforms)
  • Lenient mode to ignore unknown keys

Weaknesses

  • Specialized to pubspec files only, not a general YAML library
  • No code‑generation support
  • Adds another dependency if you already use a generic YAML parser

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
5
import 'package:pubspec_parse/pubspec_parse.dart';

void main() {
  const yaml = '''name: my_pkg\nversion: 1.0.0\ndependencies:\n  http: ^0.13.0''';
  final pubspec = Pubspec.parse(yaml);
  print(pubspec.name); // my_pkg
}

Alternatives

Packages that do the same job and could replace pubspec_parse.

  • deep_pick

    Type-safe API for manual JSON parsing with useful error messages.

  • pubspec_manager

    Type-safe API to read, modify, and write pubspec.yaml while preserving comments.

  • config

    Typed CLI argument and config file parser with env support

  • dart_either

    Either monad for Dart and Flutter supporting type-safe error handling and railway-oriented programming.

Works with

Packages commonly used together with pubspec_parse: ones it builds on, ones built on it, and its own family.