--- id: langdiff version: "0.2.0" license: Apache-2.0 license_treatment: permissive maintenance: aging --- # langdiff — LangDiff is a Python library that solves the hard problems of streaming structured LLM outputs to frontends. License: permissive · Maintenance: aging · Downloads: 130.8K/mo ## What it is and what it does LangDiff is a Python library for handling the streaming of structured LLM outputs to web frontends. It solves two core problems: parsing incomplete JSON tokens as they arrive from an LLM stream (where traditional JSON parsers fail on fragments like `{"field": "incomplete`), and decoupling frontend UI schemas from backend LLM output schemas through change-based synchronization. The library provides Pydantic-style model classes (ld.Object, ld.List, ld.String) that emit granular callbacks (on_append, on_update, on_complete) as tokens stream in, giving you type-safe partial updates. It also tracks mutations to your application objects and generates JSON Patch diffs (RFC 6902, with an additional append operation) for efficient frontend synchronization, so you send only deltas rather than full state retransmissions. Runtime dependencies are jiter, jsonpatch, jsonpointer, and pydantic. Use it for: - Stream multi-section articles or reports from LLMs, updating UI sections as titles and content arrive incrementally. - Generate structured data (e.g., product catalogs, survey responses) and send JSON Patch diffs to frontend for real-time UI updates. - Decouple LLM output schema evolution from frontend code by tracking changes and sending diffs instead of raw JSON. - Build responsive chatbots that display structured responses (lists, objects) as tokens arrive, rather than waiting for complete JSON. - Synchronize backend state mutations with frontend without retransmitting entire objects on each token. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. LangDiff streams structured LLM outputs to frontends with granular, type-safe parsing events and automatic JSON Patch generation for efficient state synchronization. Yes, if you are building an LLM-powered application that streams structured outputs and need granular, type-safe parsing with efficient frontend synchronization. The low install friction and permissive license are favorable. However, the project is very new (first release August 2025) with aging maintenance status—verify that it is actively maintained and test compatibility with your LLM provider and schema complexity before committing to production. ## Install pip install langdiff uv add langdiff poetry add langdiff ## Installing langdiff Before you install: Low friction: pure Python wheel with four runtime dependencies (jiter, jsonpatch, jsonpointer, pydantic). Maintenance status is aging—first release August 2025, latest August 2025, last commit September 2025—so the project is very new and may see breaking changes. License in practice: Apache-2.0 permissive license allows commercial use, modification, and distribution with minimal restrictions, making it suitable for proprietary applications. Quickstart: pip install langdiff import langdiff as ld class Response(ld.Object): items: ld.List[ld.String] response = Response() with ld.Parser(response) as parser: parser.push('{"items": ["example"]}') Requires Python 3.11 or later. Verify before relying: - Whether the package is actively maintained beyond its August 2025 releases or if development has stalled. - Performance characteristics when parsing very large or deeply nested JSON structures. - Compatibility with LLM providers beyond OpenAI (e.g., Anthropic, Gemini). ## Package facts - License: Apache-2.0 (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 130.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags streaming json parsing llm, structured output streaming, json patch generation, pydantic streaming parser, llm response streaming, incremental json parsing, change tracking json, llm-streaming, json-parsing, state-sync [View on SkillFed](https://skillfed.io/packages/langdiff) · [View on PyPI](https://pypi.org/project/langdiff/)