Skip to content

Python implementation of DCP (FastAPI & HTTPX support) - #2

Open
MatteoScorcia wants to merge 15 commits into
canaryfrom
python
Open

Python implementation of DCP (FastAPI & HTTPX support)#2
MatteoScorcia wants to merge 15 commits into
canaryfrom
python

Conversation

@MatteoScorcia

Copy link
Copy Markdown

This PR provides a modular Python implementation of the Differential Context Protocol (DCP), optimized for both server-side streaming and client-side consumption.

Following previous feedback, the architecture has been refined to decouple networking dependencies (FastAPI/HTTPX) into optional extras, ensuring the package remains lean and suitable for diverse environments (from
high-performance servers to lightweight background workers).

Core Features:

  • Modular Architecture: Split into [server] (FastAPI), [client] (HTTPX), and core logic (Pydantic-only) to minimize dependency overhead.
  • FastAPI / Starlette Integration: ObjectStreamResponse for turning async generators into streaming endpoints with automatic diffing.
  • Resilient Async Client: fetch_object_stream for real-time state reconstruction, featuring heartbeat support and automatic fallback to plain JSON.
  • Optimized Diffs: High-performance calculation of deltas using JSON Pointers (RFC 6901) and specialized string-append operations.
  • Dictionary-based Path Compression: 95%+ compression efficiency during transmission for redundant JSON paths.
  • Legacy Compatibility: Supports Python 3.10+.

@MatteoScorcia

Copy link
Copy Markdown
Author

I have completely refactored the original Python implementation to address the modularity concerns. The package now features a clean import tree, supports Python 3.10+, and cleanly separates the server and client logic into optional extras while maintaining the full feature set of the DCP specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant