Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Open Postgres Checkpointer

CI PyPI Python 3.11–3.14 License: Apache-2.0 Typed Docs

A drop-in LangGraph PostgreSQL checkpointer that cuts disk usage 4×–12.5× using flat zstd patches, lock-free pooled concurrency, optimistic thread fencing, and production lifecycle primitives — on upstream's own tables.

Documentation · Why & How It Works · Quickstart · Benchmarks · Changelog

Status: 1.0.0rc1 is a release candidate. Tested against upstream's langgraph-checkpoint-conformance suite. Please report bugs or edge cases in GitHub Issues.


Why Open Postgres Checkpointer?

Upstream's langgraph-checkpoint-postgres rewrites every changed channel value in full at every step (causing O(N²) disk and WAL growth on growing chat/agent state), serializes all traffic behind a single saver-wide asyncio.Lock, lets concurrent runs on one thread silently fork history, refuses to prune DeltaChannel threads, and omits operational primitives like thread listing and idle-thread expiry.

Open Postgres Checkpointer implements LangGraph's BaseCheckpointSaver directly on upstream's existing four tables — adopting existing databases in place with no data migration:

Capability langgraph-checkpoint-postgres open-postgres-checkpointer
Disk on plain graphs O(N²) full rewrites every step 4.0×–12.5× smaller via flat zstd-prefix patches (no graph changes)
Concurrency Single saver-wide asyncio.Lock Lock-free connection pool + single-statement atomic put / put_writes (1.5×–1.7× turns/s)
Racing writers on one thread Silently forks history Optimistic fence raises ThreadConflictError
Retention & pruning Refuses DeltaChannel threads aprune / prune works on DeltaChannel, plus keep_last=N thinning and adelete_for_runs
Thread operations Manual SQL Indexed alist_threads / list_threads, acopy_thread, and idle-thread asweep_expired
Adoption & rollback — Reads all upstream rows in place; full_copies_only=True rollout; online rollback via opc-rehydrate

For turn-by-turn diagrams of how upstream stores checkpoints and how each optimization works, see Why & How It Works.


Installation

pip install --pre "open-postgres-checkpointer[binary]"

Or with uv:

uv add "open-postgres-checkpointer[binary]>=1.0.0rc1"
  • [binary] installs psycopg's bundled libpq. If your environment already provides PostgreSQL's libpq, you can install bare open-postgres-checkpointer (or [c] for psycopg's C extension). Importing without a libpq backend raises ImportError: no pq wrapper available.
  • --pre is required while only release candidates are published.

Quickstart

from open_postgres_checkpointer import AsyncOpenPostgresCheckpointer

async with AsyncOpenPostgresCheckpointer.from_conn_string(DB_URI) as saver:
    await saver.setup()  # once, from one process
    graph = builder.compile(checkpointer=saver)
    result = await graph.ainvoke(inputs, {"configurable": {"thread_id": "t1"}})

You can also pass an existing psycopg_pool.AsyncConnectionPool configured with kwargs={"autocommit": True} directly to async with AsyncOpenPostgresCheckpointer(pool) as saver:.

Sync

For code without an event loop of its own, OpenPostgresCheckpointer provides the same behavior over a private background loop thread:

from open_postgres_checkpointer import OpenPostgresCheckpointer

with OpenPostgresCheckpointer.from_conn_string(DB_URI) as saver:
    saver.setup()  # once, from one process
    graph = builder.compile(checkpointer=saver)
    result = graph.invoke(inputs, {"configurable": {"thread_id": "t1"}})

Production Primitives

List threads (indexed, metadata-filtered, cursor-paged)

from open_postgres_checkpointer import alist_threads

page = [t async for t in alist_threads(saver, filter={"user_id": "u1"}, limit=20)]
next_page = [
    t
    async for t in alist_threads(
        saver, filter={"user_id": "u1"}, before=page[-1].config, limit=20
    )
]

(Sync callers use list_threads(saver, ...).)

Retention, thinning, and idle-thread expiry

from datetime import timedelta

# Thin history: keep the last 10 checkpoints per namespace + each run's final checkpoint
await saver.aprune(["t1", "t2"], keep_last=10)

# Delete threads idle for more than 30 days (safe alongside live runs)
report = await saver.asweep_expired(timedelta(days=30), max_threads=100)

# Remove checkpoints belonging to specific runs, or clone a thread for branching/replay
await saver.adelete_for_runs(["run-123"])
await saver.acopy_thread("t1", "t1-fork")

Optimistic concurrency fence

Every read mints a lightweight generation token carried through LangGraph's configurable dict. If two runs race on the same thread, the stale writer is refused with ThreadConflictError instead of silently overwriting or forking history:

from open_postgres_checkpointer import ThreadConflictError

try:
    await graph.ainvoke(inputs, config)
except ThreadConflictError:
    # Reload latest state or surface a conflict to the caller
    ...

How Patch Storage Works

Changed channel values ≥ 1 KiB are compressed as a flat zstd-prefix patch against an earlier full copy (the base) stored in upstream's checkpoint_blobs table. Every base is a full copy — never a patch — so reads apply at most one patch regardless of thread length:

checkpoint_blobs
  v1 (base)   ──► opc:zstd:msgpack         (compressed full copy + zstd checksum)
  v2 (patch)  ──► opc:zstd-patch:msgpack   (small delta against v1; 1 hop to decode)
  v3 (patch)  ──► opc:zstd-patch:msgpack   (small delta against v1; still 1 hop)
  vN (new)    ──► opc:zstd:msgpack         (new base once patch > 25% of base size)
  • Wire-skip warm reads: An in-memory LRU BaseCache (64 MiB default) caches base bytes and ZstdDict prefixes so warm reads skip re-fetching the base blob over the wire.
  • Database-enforced integrity: A DEFERRABLE INITIALLY DEFERRED foreign key in opc_blob_patch prevents orphaned patches, and zstd content checksums verify every decoded frame.
  • Off the event loop: All serialization, compression, and decoding run on a dedicated single codec thread per saver.

Benchmarks

Measured before the first release on an uncontended benchmark host with PostgreSQL 16 and 8 pool connections per arm. Disk is bytes above each arm's empty schema after VACUUM, including our side tables and indexes. Ratios are against upstream's AsyncPostgresSaver:

Workload Disk vs. upstream put p50 vs. upstream
400-step chat, plain graph 6.9× smaller 0.41×
400-step chat, DeltaChannel graph 0.95× 0.65×
Agent thread growing to 1 / 3 / 10 MB, plain graph 4.0× / 5.7× / 12.5× smaller 0.43× / 0.34× / 0.15×
Agent thread growing to 1 / 3 / 10 MB, DeltaChannel graph 1.06× / 0.93× / 0.84× 1.39× / 1.81× / 1.76× (cold pool)
8 / 32 concurrent threads, plain graph — 0.53× / 0.47× (1.7× / 1.6× turns/s)
8 / 32 concurrent threads, DeltaChannel graph — 0.21× / 0.21× (1.5× / 1.5× turns/s)

Note on the cold-pool DeltaChannel cells: Bold cells exceed the acceptance bars (DeltaChannel disk ≤ 1.05×, put p50 ≤ 1.25×) on a brand-new connection pool because the larger put statement (which also maintains opc_thread_head and the listing index) costs more to plan on first execution (analysis). On a warm long-lived pool, the same DeltaChannel puts measure 0.72×–1.16× upstream (ADR-0030).

Reproduce locally with benchmarks/README.md:

just bench-case smoke     # quick setup check
just bench-case four-arm  # 400-step chat + concurrent arms
just bench-case large     # 1 / 3 / 10 MB agent threads

Safe Rollout & Rollback

  1. Adopt in place: Open Postgres Checkpointer reads every row upstream wrote. Once a patch is stored on a thread, upstream's saver cannot read that thread and raises loudly rather than returning partial state.
  2. Zero-downtime rollout: Deploy initially with full_copies_only=True while upstream replicas are still running, then enable patching once all replicas run this saver (Adopting the saver).
  3. Online rollback: opc-rehydrate rewrites every patch and compressed row back to plain upstream format in resumable, memory-bounded batches while savers keep running:
opc-rehydrate "$DB_URI" --dry-run   # estimate row counts and disk needed
opc-rehydrate "$DB_URI"             # or: python -m open_postgres_checkpointer.rehydrate

See Rolling back for the full procedure and dropping our side tables.


Supported Versions

Component Supported
Python 3.11, 3.12, 3.13, 3.14 (compression.zstd stdlib on 3.14+; backports.zstd before)
PostgreSQL 15, 16 (required weekly matrix); 17, 18 tested weekly
langgraph-checkpoint >=4.3.1, <5
langgraph-checkpoint-postgres schema 3.2.0 (vendored migrations; not a runtime dependency)
psycopg / psycopg-pool >=3.3.6 / >=3.2

Documentation


Development

This project uses uv and just (plus a Dev Container):

just install     # sync all dependency groups + install pre-commit hooks
just check       # lint, fmt-check, typecheck, and unit tests
just test-int    # integration + upstream conformance suite (needs Docker)
just docs        # strict MkDocs build

See CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.

License & Attribution

Licensed under the Apache License, Version 2.0 — see NOTICE and THIRD_PARTY_NOTICES.md for attribution and vendored upstream schema migrations.

PostgreSQL and Postgres are registered trademarks of the PostgreSQL Community Association of Canada (PGCAC). LangGraph and LangChain are trademarks of LangChain, Inc. Open Postgres Checkpointer is an independent open-source project and is not affiliated with, endorsed by, or sponsored by the PostgreSQL Global Development Group, PGCAC, or LangChain, Inc.

Metadata

Release files for open-postgres-checkpointer 1.0.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for open-postgres-checkpointer 1.0.0rc2
File Size Uploaded Provenance Actions
open_postgres_checkpointer-1.0.0rc2.tar.gz 77.7 kB With provenance Details for open_postgres_checkpointer-1.0.0rc2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for open-postgres-checkpointer 1.0.0rc2
File Interpreter ABI Platform Actions
open_postgres_checkpointer-1.0.0rc2-py3-none-any.whl Python 3 none any Details for open_postgres_checkpointer-1.0.0rc2-py3-none-any.whl

Total release size: 158.0 kB

Release files / open_postgres_checkpointer-1.0.0rc2.tar.gz

Download URL open_postgres_checkpointer-1.0.0rc2.tar.gz
Size 77.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ca4275e3ab638176f372e10e5a8aee482a4c63edfc019552beff3561b6e94d63
BLAKE2b-256 checksum
How to use checksums
6b71ee6d5706b38a0fb8b6a73a2ed43a690420de2c6c851375e35c66a3adcf28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Release files / open_postgres_checkpointer-1.0.0rc2-py3-none-any.whl

Download URL open_postgres_checkpointer-1.0.0rc2-py3-none-any.whl
Size 80.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63e522120c584a0ad05bfe1cdabad53a9897501a07f21c8cd43eb92cc0ca4e75
BLAKE2b-256 checksum
How to use checksums
a5e240378987e36e841ba94975159d4e363ad297fbf3f434281f973e01a714f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Security for open-postgres-checkpointer 1.0.0rc2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for open_postgres_checkpointer-1.0.0rc2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page